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_title: "New Crowdin translations"
|
||||||
pull_request_body: ""
|
pull_request_body: ""
|
||||||
source: "source.yaml"
|
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 }}
|
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
|
||||||
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
||||||
env:
|
env:
|
||||||
|
2
.github/workflows/crowdin-upload.yaml
vendored
2
.github/workflows/crowdin-upload.yaml
vendored
@ -28,7 +28,7 @@ jobs:
|
|||||||
download_translations: false
|
download_translations: false
|
||||||
localization_branch_name: i18n
|
localization_branch_name: i18n
|
||||||
source: "source.yaml"
|
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 }}
|
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
|
||||||
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
||||||
env:
|
env:
|
||||||
|
@ -458,11 +458,7 @@ public abstract class AbstractDiscordSRV<
|
|||||||
if (config != null) {
|
if (config != null) {
|
||||||
String defaultLanguage = config.messages.defaultLanguage;
|
String defaultLanguage = config.messages.defaultLanguage;
|
||||||
if (StringUtils.isNotBlank(defaultLanguage)) {
|
if (StringUtils.isNotBlank(defaultLanguage)) {
|
||||||
for (Locale locale : Locale.getAvailableLocales()) {
|
return Locale.forLanguageTag(defaultLanguage);
|
||||||
if (locale.getISO3Language().equals(defaultLanguage)) {
|
|
||||||
return locale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
|
|||||||
private final Map<Locale, MessagesConfigSingleManager<C>> configs = new LinkedHashMap<>();
|
private final Map<Locale, MessagesConfigSingleManager<C>> configs = new LinkedHashMap<>();
|
||||||
private final DiscordSRV discordSRV;
|
private final DiscordSRV discordSRV;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private boolean multi;
|
|
||||||
|
|
||||||
public MessagesConfigManager(DiscordSRV discordSRV) {
|
public MessagesConfigManager(DiscordSRV discordSRV) {
|
||||||
this.discordSRV = discordSRV;
|
this.discordSRV = discordSRV;
|
||||||
@ -45,10 +44,7 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
|
|||||||
throw new ConfigException("MainConfig not available");
|
throw new ConfigException("MainConfig not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean multiple = config.messages.multiple;
|
if (config.messages.multiple) {
|
||||||
Locale defaultLocale = discordSRV.defaultLocale();
|
|
||||||
|
|
||||||
if (multiple) {
|
|
||||||
try {
|
try {
|
||||||
Path messagesDirectory = directory();
|
Path messagesDirectory = directory();
|
||||||
if (!Files.exists(messagesDirectory)) {
|
if (!Files.exists(messagesDirectory)) {
|
||||||
@ -83,7 +79,8 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
|
|||||||
throw new ConfigException("Failed to initialize messages configs", t);
|
throw new ConfigException("Failed to initialize messages configs", t);
|
||||||
}
|
}
|
||||||
} else {
|
} 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()) {
|
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 {
|
private ConfigurationNode getTranslationRoot() throws ConfigurateException {
|
||||||
String languageCode = locale().getISO3Language();
|
String languageCode = locale().getLanguage();
|
||||||
|
String countryCode = locale().getCountry();
|
||||||
|
|
||||||
ClassLoader classLoader = discordSRV.getClass().getClassLoader();
|
ClassLoader classLoader = discordSRV.getClass().getClassLoader();
|
||||||
URL resourceURL = classLoader.getResource("translations/" + languageCode + ".yaml");
|
|
||||||
|
URL resourceURL = classLoader.getResource("translations/" + languageCode + "_" + countryCode + ".yaml");
|
||||||
if (resourceURL == null) {
|
if (resourceURL == null) {
|
||||||
resourceURL = classLoader.getResource("translations/eng.yaml");
|
resourceURL = classLoader.getResource("translations/" + languageCode + ".yaml");
|
||||||
}
|
}
|
||||||
if (resourceURL == null) {
|
if (resourceURL == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -6,10 +6,11 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
|
|||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class MessagesMainConfig {
|
public class MessagesMainConfig {
|
||||||
|
|
||||||
@Comment("The 3 letter ISO 639-2 code for the default language, if left blank the system default will be used")
|
@Comment("The language code for the default language, if left blank the system default will be used.\n"
|
||||||
public String defaultLanguage = "eng";
|
+ "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;
|
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")
|
@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