adding curly braces for all if statements
This commit is contained in:
parent
6312b966f2
commit
ae2509837e
3 changed files with 13 additions and 12 deletions
|
@ -81,8 +81,9 @@ public class LocaleSelectionDataGetter implements DataGetter {
|
|||
for(final Locale locale: selectables) {
|
||||
setOfLocalesBase.add(locale.stripExtensions().toLanguageTag());
|
||||
}
|
||||
if (setOfLocalesBase.size() < selectables.size())
|
||||
if (setOfLocalesBase.size() < selectables.size()) {
|
||||
includeAbbreviation = true;
|
||||
}
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Locale locale : selectables) {
|
||||
try {
|
||||
|
@ -102,8 +103,9 @@ public class LocaleSelectionDataGetter implements DataGetter {
|
|||
map.put("code", locale.toLanguageTag().replace('-','_'));
|
||||
map.put("label", locale.getDisplayLanguage(locale));
|
||||
map.put("country", locale.getDisplayCountry(locale));
|
||||
if (includeAbbreviation)
|
||||
if (includeAbbreviation) {
|
||||
map.put("institution", Optional.ofNullable(locale.getExtension(LocaleSelectionDataGetter.PRIVATE_USE_SUBTAG)).orElse("").toUpperCase());
|
||||
}
|
||||
map.put("selected", currentLocale.equals(locale));
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -137,15 +137,17 @@ public class RDFFilesLoader {
|
|||
List<Locale> locales = SelectedLocale.getSelectableLocales(ctx);
|
||||
for (Locale locale : locales) {
|
||||
String localeString = locale.toLanguageTag().replace('-', '_');
|
||||
if (! enabledLocales.contains(localeString))
|
||||
if (! enabledLocales.contains(localeString)) {
|
||||
enabledLocales.add(localeString);
|
||||
}
|
||||
// If a locale with fr_CA_x_uqam is used, the locale fr_CA should be also enabled for loading.
|
||||
// Private tags (lang_CountryCode_x_InstitutionAbbreviation) are inteded to be just extension,
|
||||
// therefore the basic locale (lang_CountryCode) should be loaded as well.
|
||||
if(locale.hasExtensions()){
|
||||
localeString = locale.stripExtensions().toLanguageTag().replace('-', '_');
|
||||
if (! enabledLocales.contains(localeString))
|
||||
if (! enabledLocales.contains(localeString)) {
|
||||
enabledLocales.add(localeString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,18 +11,15 @@ public final class LocaleUtility {
|
|||
public static Locale languageStringToLocale(String localeString){
|
||||
String[] parsedLoc = localeString.trim().split("_", -1);
|
||||
Locale locale = null;
|
||||
//regex pattern for locale tag with script and private-use subtag, e.g. sr_Latn_RS_x_uns
|
||||
if (localeString.matches("^[a-z]{1,3}_[A-Z][a-z]{3}_[A-Z]{2}_x_[a-z]{1,}"))
|
||||
if (localeString.matches("^[a-z]{1,3}_[A-Z][a-z]{3}_[A-Z]{2}_x_[a-z]{1,}")) { //regex pattern for locale tag with script and private-use subtag, e.g. sr_Latn_RS_x_uns
|
||||
locale = new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[2]).setScript(parsedLoc[1]).setExtension('x', parsedLoc[4]).build();
|
||||
//regex pattern for locale tag with script and private-use subtag, e.g. fr_CA_x_uqam
|
||||
if (localeString.matches("^[a-z]{1,3}_[A-Za-z]{2}_x_[a-z]{1,}"))
|
||||
} else if (localeString.matches("^[a-z]{1,3}_[A-Za-z]{2}_x_[a-z]{1,}")) { //regex pattern for locale tag with script and private-use subtag, e.g. fr_CA_x_uqam
|
||||
locale = new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[1]).setExtension('x', parsedLoc[3]).build();
|
||||
//regex pattern for locale tag with script specified, e.g. sr_Latn_RS
|
||||
else if (localeString.matches("^[a-z]{1,3}_[A-Z][a-z]{3}_[A-Z]{2}"))
|
||||
} else if (localeString.matches("^[a-z]{1,3}_[A-Z][a-z]{3}_[A-Z]{2}")) { //regex pattern for locale tag with script specified, e.g. sr_Latn_RS
|
||||
locale = new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[2]).setScript(parsedLoc[1]).build();
|
||||
// other, just languge, e.g. es, or language + region, e.g. en_US, pt_BR, ru_RU, etc.
|
||||
else
|
||||
} else { // other, just languge, e.g. es, or language + region, e.g. en_US, pt_BR, ru_RU, etc.
|
||||
locale = LocaleUtils.toLocale(localeString);
|
||||
}
|
||||
String localeLang = locale.toLanguageTag();
|
||||
return locale;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue