public ILocalizedText getLocalizedText(Locale locale, final String id)
{
// We hard-code our package name in here, so that callers can use
// a short string
ILocalizedText localizedText = m_resourceBundleLocalizer.getLocalizedText(locale, m_prefix + id);
// If no ILocalizedText was found, try English
if (localizedText == null && !Locale.getDefault().getLanguage().equals("en")) //$NON-NLS-1$
{
localizedText = m_resourceBundleLocalizer.getLocalizedText(Locale.ENGLISH, m_prefix + id);
}
// If still no ILocalizedText was found, create a default one
if (localizedText == null)
{
localizedText = new ILocalizedText()
{
public String format(Map parameters)
{
StringBuilder sb = new StringBuilder();
sb.append('!');
sb.append(id);
sb.append('!');
if (parameters != null && !parameters.isEmpty())
{
sb.append(' ');
sb.append(parameters.toString());
}
return sb.toString();
}
};
}
// If the current platform's newline sequence is something other
// than "\n", then replace all occurrences of "\n" with this platform's
// newline sequence.
if (m_newline.equals("\n")) //$NON-NLS-1$
{
return localizedText;
}
else
{
final ILocalizedText finalLocalizedText = localizedText;
return new ILocalizedText()
{
public String format(Map parameters)
{
String result = finalLocalizedText.format(parameters);
return result.replaceAll("\n", m_newline); //$NON-NLS-1$
}
};
}
}