diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-07-22 16:42:41 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-07-22 16:45:49 +0200 |
commit | e0e528211faad3fdf469c83bcbc7aecf6c25a234 (patch) | |
tree | a912cbe6bed9c5f157a7dd9c71c27d8d0fc4d301 /plugins/sonar-core-plugin | |
parent | 74cf33e4a17c24df8ea1c8eb51fe5a38ad821be9 (diff) | |
download | sonarqube-e0e528211faad3fdf469c83bcbc7aecf6c25a234.tar.gz sonarqube-e0e528211faad3fdf469c83bcbc7aecf6c25a234.zip |
SONAR-2589 Fix bug with I18n rule description
If a rule description is not available in the locale of the user,
the english one is not used.
This is fixed now.
Diffstat (limited to 'plugins/sonar-core-plugin')
5 files changed, 27 insertions, 7 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java index 1e23ab2c109..67c9b4f467f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/i18n/I18nManager.java @@ -211,13 +211,15 @@ public final class I18nManager implements I18n, ServerExtension, BatchExtension if (bundleBaseName == null) { handleMissingBundle(ruleNameKey, defaultText, bundleBaseName); } else { - Locale localeToUse = defineLocaleToUse(locale); - String htmlFilePath = computeHtmlFilePath(bundleBaseName, ruleDescriptionKey, localeToUse); - ClassLoader classLoader = bundleClassLoader.getClassLoaderForBundle(bundleBaseName, localeToUse); - InputStream stream = classLoader.getResourceAsStream(htmlFilePath); + InputStream stream = extractRuleDescription(locale, ruleDescriptionKey, bundleBaseName); + if (stream == null && !Locale.ENGLISH.equals(locale)) { + // let's try in the ENGLISH bundles + stream = extractRuleDescription(Locale.ENGLISH, ruleDescriptionKey, bundleBaseName); + } if (stream == null) { - throw new MissingResourceException("MISSING RULE DESCRIPTION : file '" + htmlFilePath - + "' not found in any bundle. Default value is returned.", bundleBaseName, ruleDescriptionKey); + // Definitely, no HTML file found for the description of this rule... + throw new MissingResourceException("MISSING RULE DESCRIPTION : HTML file not found in any bundle. Default value is returned.", + bundleBaseName, ruleDescriptionKey); } translation = IOUtils.toString(stream, "UTF-8"); } @@ -225,6 +227,14 @@ public final class I18nManager implements I18n, ServerExtension, BatchExtension return translation; } + private InputStream extractRuleDescription(final Locale locale, final String ruleDescriptionKey, String bundleBaseName) { + Locale localeToUse = defineLocaleToUse(locale); + String htmlFilePath = computeHtmlFilePath(bundleBaseName, ruleDescriptionKey, localeToUse); + ClassLoader classLoader = bundleClassLoader.getClassLoaderForBundle(bundleBaseName, localeToUse); + InputStream stream = classLoader.getResourceAsStream(htmlFilePath); + return stream; + } + protected Locale defineLocaleToUse(final Locale locale) { Locale localeToUse = locale; if ( !registeredLocales.contains(locale)) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java index bf66390c9e6..b3f48fd42ce 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/i18n/I18nManagerTest.java @@ -146,6 +146,13 @@ public class I18nManagerTest { assertThat(result, is("<h1>Fake Rule</h1>\nThis is the description of the fake rule.")); } + @Test + public void shouldReturnEnglishRuleDescriptionFromMissingHTMLFileInFrench() throws Exception { + String result = manager.message(Locale.FRENCH, "rule.test.anotherfakerule.description", "foo"); + assertThat(result, is("<h1>Another Fake Rule</h1>\nThis is the description of the fake rule.")); + + } + public static class TestClassLoader extends URLClassLoader { public TestClassLoader(URL url) { diff --git a/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar Binary files differindex 14d66ce530d..f593384a2ab 100755 --- a/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin.jar diff --git a/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test.properties b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test.properties index 7aba645661f..207a12a76a8 100644 --- a/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test.properties +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test.properties @@ -2,4 +2,5 @@ it=It is=is cold=cold only.english=Ketchup -rule.test.fakerule.name=Fake Rule
\ No newline at end of file +rule.test.fakerule.name=Fake Rule +rule.test.anotherfakerule.name=Another Fake Rule
\ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test/anotherfakerule.html b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test/anotherfakerule.html new file mode 100644 index 00000000000..60539d00c95 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/resources/I18n/EnglishPlugin/org/sonar/i18n/test/anotherfakerule.html @@ -0,0 +1,2 @@ +<h1>Another Fake Rule</h1> +This is the description of the fake rule.
\ No newline at end of file |