Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include Uzbek variants in default DB locales #19783

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public I18nLocalePopulator(I18nLocaleService localeService) {
private static final Set<String> DEFAULT_LOCALES =
Set.of(
"af", "ar", "bi", "am", "de", "dz", "en", "es", "fa", "fr", "gu", "hi", "id", "it", "km",
"lo", "my", "ne", "nl", "no", "ps", "pt", "ru", "rw", "sw", "tg", "vi", "zh");
"lo", "my", "ne", "nl", "no", "ps", "pt", "ru", "rw", "sw", "tg", "uz__latn", "uz__cyrl", "vi", "zh"
);
Philip-Larsen-Donnelly marked this conversation as resolved.
Show resolved Hide resolved

@Override
public void executeInTransaction() {
Expand All @@ -65,10 +66,33 @@ public void executeInTransaction() {
return;
}

for (String locale : DEFAULT_LOCALES) {
localeService.saveI18nLocale(new I18nLocale(new Locale(locale)), new SystemUser());
for (String localeStr : DEFAULT_LOCALES) {
Locale locale = parseLocaleString(localeStr);
localeService.saveI18nLocale(new I18nLocale(locale), new SystemUser());
}

log.info("Populated default locales");
}

/**
* Parses a locale string into a Locale object.
*
* @param localeStr the locale string to parse
* @return the parsed Locale object
* @throws IllegalArgumentException if the locale string is invalid
*
* Supports locales of the form <lang>[_<country>[_<variant>]]
*/
private Locale parseLocaleString(String localeStr) {
if (!localeStr.contains("_")) {
return new Locale(localeStr);
}

String[] parts = localeStr.split("_");
return switch (parts.length) {
case 2 -> new Locale(parts[0], parts[1]);
case 3 -> new Locale(parts[0], parts[1], parts[2]);
default -> throw new IllegalArgumentException("Invalid locale format: " + localeStr);
};
}
}
Loading