// First, we check if the bundle exists in the language pack classloader
resourceBundle = ResourceBundle.getBundle(bundleKey, locale, languagePackClassLoader);
String message = resourceBundle.getString(key);
- return MessageFormat.format(message, parameters);
+ return formatMessage(message, parameters);
} catch (MissingResourceException e1) {
// well, maybe the plugin has specified its own bundles, let's see
resourceBundle = getBundleFromCorrespondingPluginClassloader(bundleKey, locale);
if (value == null) {
value = defaultValue;
}
- if (value != null && parameters.length > 0) {
- return MessageFormat.format(value, parameters);
+ return formatMessage(value, parameters);
+ }
+
+ private String formatMessage(String message, Object... parameters) {
+ if (message == null || parameters.length == 0) {
+ return message;
}
- return value;
+ return MessageFormat.format(message.replaceAll("'", "''"), parameters);
}
String extractBundleFromKey(String key) {
@Test
public void shouldLookInCoreClassloaderForPluginsThatDontEmbedAllLanguages() {
assertThat(manager.message(Locale.ENGLISH, "forge_plugin.page", null)).isEqualTo("This is my plugin");
- assertThat(manager.message(Locale.FRENCH, "forge_plugin.page", null)).isEqualTo("Mon plugin!");
+ assertThat(manager.message(Locale.FRENCH, "forge_plugin.page", null)).isEqualTo("C'est mon plugin");
}
// see SONAR-3783 => test that there will be no future regression on fallback for keys spread accross several classloaders
@Test
public void shouldFallbackOnOriginalPluginIfTranslationNotPresentInLanguagePack() {
// the "forge_plugin.page" has been translated in French
- assertThat(manager.message(Locale.FRENCH, "forge_plugin.page", null)).isEqualTo("Mon plugin!");
+ assertThat(manager.message(Locale.FRENCH, "forge_plugin.page", null)).isEqualTo("C'est mon plugin");
// but not the "forge_plugin.key_not_translated" key
assertThat(manager.message(Locale.FRENCH, "forge_plugin.key_not_translated", null)).isEqualTo("Key Not Translated");
}