diff options
author | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2012-10-09 17:05:07 +0200 |
---|---|---|
committer | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2012-10-09 17:14:06 +0200 |
commit | 74b3c07ff473ffc83b111a3ae05e2bf6fb3940b7 (patch) | |
tree | 0c2b9c0a1c3e7d33e539bc7c97ca9da0fc72e0b6 /sonar-core | |
parent | 062ba55d6a9beb304e3bb454ce974884afbb52ef (diff) | |
download | sonarqube-74b3c07ff473ffc83b111a3ae05e2bf6fb3940b7.tar.gz sonarqube-74b3c07ff473ffc83b111a3ae05e2bf6fb3940b7.zip |
SONAR-3783 Fix regression on single quotes used with parameters
Diffstat (limited to 'sonar-core')
3 files changed, 11 insertions, 7 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java index 3125faea3fb..922710e4311 100644 --- a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java +++ b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java @@ -113,7 +113,7 @@ public class I18nManager implements I18n, ServerExtension, BatchExtension { // 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); @@ -214,10 +214,14 @@ public class I18nManager implements I18n, ServerExtension, BatchExtension { 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) { diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/I18nManagerTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/I18nManagerTest.java index 5a2d6e8205f..19cb921cf75 100644 --- a/sonar-core/src/test/java/org/sonar/core/i18n/I18nManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/i18n/I18nManagerTest.java @@ -212,14 +212,14 @@ public class I18nManagerTest { @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"); } diff --git a/sonar-core/src/test/resources/org/sonar/core/i18n/frenchPack/org/sonar/l10n/forge_fr.properties b/sonar-core/src/test/resources/org/sonar/core/i18n/frenchPack/org/sonar/l10n/forge_fr.properties index 9d06fab3ec7..96fb089d580 100644 --- a/sonar-core/src/test/resources/org/sonar/core/i18n/frenchPack/org/sonar/l10n/forge_fr.properties +++ b/sonar-core/src/test/resources/org/sonar/core/i18n/frenchPack/org/sonar/l10n/forge_fr.properties @@ -1 +1 @@ -forge_plugin.page=Mon plugin!
\ No newline at end of file +forge_plugin.page=C'est mon plugin
\ No newline at end of file |