diff options
author | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2012-10-30 17:11:34 +0100 |
---|---|---|
committer | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2012-10-30 17:13:51 +0100 |
commit | 416679f465a455779219f09fc466dfa173f1003e (patch) | |
tree | 30d3d3d1c8a0d2cfd42049ca6f4fdcb107abda7e | |
parent | 1f2867f662f498572102b0a0b940e4aa7e4421f3 (diff) | |
download | sonarqube-416679f465a455779219f09fc466dfa173f1003e.tar.gz sonarqube-416679f465a455779219f09fc466dfa173f1003e.zip |
SONAR-3910 Handle the case of rule not translated
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java | 6 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/i18n/I18nManagerTest.java | 9 |
2 files changed, 12 insertions, 3 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 694536a23df..ccdc1fffb25 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 @@ -110,6 +110,11 @@ public class I18nManager implements I18n, ServerExtension, BatchExtension { String result = null; String bundleBase = propertyToBundles.get(relatedProperty); + if (bundleBase == null) { + // this property has no translation + return null; + } + String filePath = bundleBase.replace('.', '/'); if (!"en".equals(locale.getLanguage())) { filePath += "_" + locale.getLanguage(); @@ -155,7 +160,6 @@ public class I18nManager implements I18n, ServerExtension, BatchExtension { return MessageFormat.format(message.replaceAll("'", "''"), parameters); } - ClassLoader getBundleClassLoader() { return i18nClassloader; } 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 2e7b527c66d..44d62b70956 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 @@ -61,7 +61,7 @@ public class I18nManagerTest { List<PluginMetadata> plugins = Arrays.asList(newPlugin("sqale"), newPlugin("frpack"), newPlugin("core"), newPlugin("checkstyle"), newPlugin("other")); when(pluginRepository.getMetadata()).thenReturn(plugins); - I18nClassloader i18nClassloader = new I18nClassloader(new ClassLoader[]{ + I18nClassloader i18nClassloader = new I18nClassloader(new ClassLoader[] { newCoreClassloader(), newFrenchPackClassloader(), newSqaleClassloader(), newCheckstyleClassloader() }); manager = new I18nManager(pluginRepository); @@ -109,7 +109,6 @@ public class I18nManagerTest { assertThat(manager.message(Locale.CHINA, "sqale.page", null)).isEqualTo("Sqale page title"); } - @Test public void should_return_default_value_if_missing_key() { assertThat(manager.message(Locale.ENGLISH, "unknown", "default")).isEqualTo("default"); @@ -146,6 +145,12 @@ public class I18nManagerTest { } @Test + public void should_return_null_if_rule_not_internationalized() { + String html = manager.messageFromFile(Locale.ENGLISH, "UnknownRule.html", "foo.rule1.name", false); + assertThat(html).isNull(); + } + + @Test public void should_locate_french_file() { String html = manager.messageFromFile(Locale.FRENCH, "ArchitectureRule.html", "checkstyle.rule1.name", false); assertThat(html).isEqualTo("Règle d'architecture"); |