aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-05-11 15:26:03 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-05-12 12:37:19 +0200
commitb451f859c4fc8e0a694c18e175ddc931e1702cd9 (patch)
tree5058793bdd549539bd6de42c905dc70891862b00 /sonar-core
parent4367c635b9e660bec4e30929143d6b1bfd32f2de (diff)
downloadsonarqube-b451f859c4fc8e0a694c18e175ddc931e1702cd9.tar.gz
sonarqube-b451f859c4fc8e0a694c18e175ddc931e1702cd9.zip
SONAR-9193 WS api/l10n/index returns the effective BCP47 language tag used
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java8
-rw-r--r--sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java1
2 files changed, 8 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java b/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
index 42a1707e182..ae746c6580b 100644
--- a/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
+++ b/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
@@ -226,8 +226,14 @@ public class DefaultI18n implements I18n, Startable {
return propertyToBundles.keySet();
}
+ public Locale getEffectiveLocale(Locale locale) {
+ Locale bundleLocale = ResourceBundle.getBundle(BUNDLE_PACKAGE + "core", locale, this.classloader, this.control).getLocale();
+ locale.getISO3Language();
+ return bundleLocale.getLanguage().isEmpty() ? Locale.ENGLISH : bundleLocale;
+ }
+
@CheckForNull
- private String formatMessage(@Nullable String message, Object... parameters) {
+ private static String formatMessage(@Nullable String message, Object... parameters) {
if (message == null || parameters.length == 0) {
return message;
}
diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java
index 409d7d94eaf..985810e8cb6 100644
--- a/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java
@@ -145,6 +145,7 @@ public class DefaultI18nTest {
assertThat(underTest.message(Locale.CHINA, "checkstyle.rule1.name", null)).isEqualTo("Rule one");
assertThat(underTest.message(Locale.CHINA, "any", null)).isEqualTo("Any");
assertThat(underTest.message(Locale.CHINA, "sqale.page", null)).isEqualTo("Sqale page title");
+ assertThat(underTest.getEffectiveLocale(Locale.CHINA)).isEqualTo(Locale.ENGLISH);
}
@Test