adding curly braces for all if statements

This commit is contained in:
Dragan Ivanovic 2022-12-13 14:37:23 +01:00
parent 6312b966f2
commit ae2509837e
3 changed files with 13 additions and 12 deletions

View file

@ -81,8 +81,9 @@ public class LocaleSelectionDataGetter implements DataGetter {
for(final Locale locale: selectables) { for(final Locale locale: selectables) {
setOfLocalesBase.add(locale.stripExtensions().toLanguageTag()); setOfLocalesBase.add(locale.stripExtensions().toLanguageTag());
} }
if (setOfLocalesBase.size() < selectables.size()) if (setOfLocalesBase.size() < selectables.size()) {
includeAbbreviation = true; includeAbbreviation = true;
}
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (Locale locale : selectables) { for (Locale locale : selectables) {
try { try {
@ -102,8 +103,9 @@ public class LocaleSelectionDataGetter implements DataGetter {
map.put("code", locale.toLanguageTag().replace('-','_')); map.put("code", locale.toLanguageTag().replace('-','_'));
map.put("label", locale.getDisplayLanguage(locale)); map.put("label", locale.getDisplayLanguage(locale));
map.put("country", locale.getDisplayCountry(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("institution", Optional.ofNullable(locale.getExtension(LocaleSelectionDataGetter.PRIVATE_USE_SUBTAG)).orElse("").toUpperCase());
}
map.put("selected", currentLocale.equals(locale)); map.put("selected", currentLocale.equals(locale));
return map; return map;
} }

View file

@ -137,17 +137,19 @@ public class RDFFilesLoader {
List<Locale> locales = SelectedLocale.getSelectableLocales(ctx); List<Locale> locales = SelectedLocale.getSelectableLocales(ctx);
for (Locale locale : locales) { for (Locale locale : locales) {
String localeString = locale.toLanguageTag().replace('-', '_'); String localeString = locale.toLanguageTag().replace('-', '_');
if (! enabledLocales.contains(localeString)) if (! enabledLocales.contains(localeString)) {
enabledLocales.add(localeString); enabledLocales.add(localeString);
}
// If a locale with fr_CA_x_uqam is used, the locale fr_CA should be also enabled for loading. // 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, // Private tags (lang_CountryCode_x_InstitutionAbbreviation) are inteded to be just extension,
// therefore the basic locale (lang_CountryCode) should be loaded as well. // therefore the basic locale (lang_CountryCode) should be loaded as well.
if(locale.hasExtensions()){ if(locale.hasExtensions()){
localeString = locale.stripExtensions().toLanguageTag().replace('-', '_'); localeString = locale.stripExtensions().toLanguageTag().replace('-', '_');
if (! enabledLocales.contains(localeString)) if (! enabledLocales.contains(localeString)) {
enabledLocales.add(localeString); enabledLocales.add(localeString);
} }
} }
}
// If no languages were enabled in runtime.properties, add a fallback as the default // If no languages were enabled in runtime.properties, add a fallback as the default
if (enabledLocales.isEmpty()) { if (enabledLocales.isEmpty()) {

View file

@ -11,18 +11,15 @@ public final class LocaleUtility {
public static Locale languageStringToLocale(String localeString){ public static Locale languageStringToLocale(String localeString){
String[] parsedLoc = localeString.trim().split("_", -1); String[] parsedLoc = localeString.trim().split("_", -1);
Locale locale = null; 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,}")) { //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,}"))
locale = new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[2]).setScript(parsedLoc[1]).setExtension('x', parsedLoc[4]).build(); 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 } 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
if (localeString.matches("^[a-z]{1,3}_[A-Za-z]{2}_x_[a-z]{1,}"))
locale = new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[1]).setExtension('x', parsedLoc[3]).build(); 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}")) { //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}"))
locale = new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[2]).setScript(parsedLoc[1]).build(); 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 { // other, just languge, e.g. es, or language + region, e.g. en_US, pt_BR, ru_RU, etc.
else
locale = LocaleUtils.toLocale(localeString); locale = LocaleUtils.toLocale(localeString);
}
String localeLang = locale.toLanguageTag(); String localeLang = locale.toLanguageTag();
return locale; return locale;
} }