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

Lang keys aren't properly formatted for override files #5521

Closed
jsuarezl opened this issue Dec 12, 2021 · 0 comments · Fixed by #5522
Closed

Lang keys aren't properly formatted for override files #5521

jsuarezl opened this issue Dec 12, 2021 · 0 comments · Fixed by #5522
Labels

Comments

@jsuarezl
Copy link

What steps will reproduce the problem?

  1. Copy a lang file from reference to override inside plugins/Towny/settings/lang/.
  2. Edit any translation.

What is the expected output?

Translations from override folder should override translations from reference files.

Right now the plugin uses the player's lang for translations, these translations are stored in a Map using translation file name as key with "-" replaced by "_" as seen on

lang = lang.replace("-", "_"); // Locale#toString uses underscores instead of dashes
translations.put(lang, new HashMap<>());

override translations doesn't have this replacement when the file name is used as key
String lang = FileNameUtils.getBaseName(file.getName());
if (values != null) {
translations.computeIfAbsent(lang, k -> new HashMap<>());
for (Map.Entry<String, Object> entry : values.entrySet())
translations.get(lang).put(entry.getKey().toLowerCase(Locale.ROOT), String.valueOf(entry.getValue()));
}

Still you can just rename your translation file to match the name of the real internal name, for example copying es-ES.yml to override folder wouldn't work, but renaming es-ES.yml in override folder to es_ES.yml would work.

This method also uses the raw key, without checking if it is valid

public static void addTranslations(Map<String, Map<String, String>> addedTranslations) {
if (addedTranslations != null && !addedTranslations.isEmpty()) {
for (String language : addedTranslations.keySet())
if (addedTranslations.get(language) != null && !addedTranslations.get(language).isEmpty())
for (Map.Entry<String, String> entry : addedTranslations.get(language).entrySet()) {
translations.computeIfAbsent(language, k -> new HashMap<>());
translations.get(language).put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue());
}
}

Towny version

0.97.5.2

Server version

git-Paper-70 (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT) (Git: 8745326)

Please use Pastebin.com to link the following files

  1. Your full server startup from the logs\latest.log:
  2. Your Towny config.yml:
  3. Your townyperms.yml:
  4. Your log's error:

(optional) If this is to do with permissions,
5. Your permissions file:

(optional) If this is to do with chat,
6. Your chatconfig.yml:
7. Your channels.yml:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant