mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-01 08:39:31 +01:00
Use two letter language codes with country codes for dialects
This commit is contained in:
parent
1c24055108
commit
f8c323e7de
2
.github/workflows/crowdin-download.yaml
vendored
2
.github/workflows/crowdin-download.yaml
vendored
@ -20,7 +20,7 @@ jobs:
|
||||
pull_request_title: "New Crowdin translations"
|
||||
pull_request_body: ""
|
||||
source: "source.yaml"
|
||||
translation: "/%original_path%/src/main/resources/translations/%three_letters_code%.yaml"
|
||||
translation: "/%original_path%/src/main/resources/translations/%two_letters_code%.yaml"
|
||||
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
|
||||
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
||||
env:
|
||||
|
2
.github/workflows/crowdin-upload.yaml
vendored
2
.github/workflows/crowdin-upload.yaml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
download_translations: false
|
||||
localization_branch_name: i18n
|
||||
source: "source.yaml"
|
||||
translation: "/%original_path%/src/main/resources/translations/%three_letters_code%.yaml"
|
||||
translation: "/%original_path%/src/main/resources/translations/%two_letters_code%.yaml"
|
||||
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
|
||||
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
||||
env:
|
||||
|
@ -458,11 +458,7 @@ public abstract class AbstractDiscordSRV<
|
||||
if (config != null) {
|
||||
String defaultLanguage = config.messages.defaultLanguage;
|
||||
if (StringUtils.isNotBlank(defaultLanguage)) {
|
||||
for (Locale locale : Locale.getAvailableLocales()) {
|
||||
if (locale.getISO3Language().equals(defaultLanguage)) {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
return Locale.forLanguageTag(defaultLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
|
||||
private final Map<Locale, MessagesConfigSingleManager<C>> configs = new LinkedHashMap<>();
|
||||
private final DiscordSRV discordSRV;
|
||||
private final Logger logger;
|
||||
private boolean multi;
|
||||
|
||||
public MessagesConfigManager(DiscordSRV discordSRV) {
|
||||
this.discordSRV = discordSRV;
|
||||
@ -45,10 +44,7 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
|
||||
throw new ConfigException("MainConfig not available");
|
||||
}
|
||||
|
||||
boolean multiple = config.messages.multiple;
|
||||
Locale defaultLocale = discordSRV.defaultLocale();
|
||||
|
||||
if (multiple) {
|
||||
if (config.messages.multiple) {
|
||||
try {
|
||||
Path messagesDirectory = directory();
|
||||
if (!Files.exists(messagesDirectory)) {
|
||||
@ -83,7 +79,8 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
|
||||
throw new ConfigException("Failed to initialize messages configs", t);
|
||||
}
|
||||
} else {
|
||||
configs.put(Locale.US, new MessagesConfigSingleManager<>(discordSRV, this, Locale.US, false));
|
||||
Locale defaultLocale = discordSRV.defaultLocale();
|
||||
configs.put(defaultLocale, new MessagesConfigSingleManager<>(discordSRV, this, defaultLocale, false));
|
||||
}
|
||||
|
||||
for (Map.Entry<Locale, MessagesConfigSingleManager<C>> entry : configs.entrySet()) {
|
||||
|
@ -105,11 +105,14 @@ public abstract class TranslatedConfigManager<T extends Config, LT extends Abstr
|
||||
}
|
||||
|
||||
private ConfigurationNode getTranslationRoot() throws ConfigurateException {
|
||||
String languageCode = locale().getISO3Language();
|
||||
String languageCode = locale().getLanguage();
|
||||
String countryCode = locale().getCountry();
|
||||
|
||||
ClassLoader classLoader = discordSRV.getClass().getClassLoader();
|
||||
URL resourceURL = classLoader.getResource("translations/" + languageCode + ".yaml");
|
||||
|
||||
URL resourceURL = classLoader.getResource("translations/" + languageCode + "_" + countryCode + ".yaml");
|
||||
if (resourceURL == null) {
|
||||
resourceURL = classLoader.getResource("translations/eng.yaml");
|
||||
resourceURL = classLoader.getResource("translations/" + languageCode + ".yaml");
|
||||
}
|
||||
if (resourceURL == null) {
|
||||
return null;
|
||||
|
@ -6,10 +6,11 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
@ConfigSerializable
|
||||
public class MessagesMainConfig {
|
||||
|
||||
@Comment("The 3 letter ISO 639-2 code for the default language, if left blank the system default will be used")
|
||||
public String defaultLanguage = "eng";
|
||||
@Comment("The language code for the default language, if left blank the system default will be used.\n"
|
||||
+ "This should be in the ISO 639-1 format or ISO 639-1 (for example \"en\"), a underscore and a ISO 3166-1 country code to specify dialect (for example \"pt_BR\")")
|
||||
public String defaultLanguage = "en";
|
||||
|
||||
@Comment("If there should be multiple messages files, one for every language")
|
||||
@Comment("If there should be a messages file per language (based on the player's or user's language), otherwise using the default")
|
||||
public boolean multiple = false;
|
||||
|
||||
@Comment("If all languages provided with DiscordSRV should be loaded into the messages directory, only functions when \"multiple\" is set to true")
|
||||
|
Loading…
Reference in New Issue
Block a user