Skip to content

Commit f0e9eb1

Browse files
committed
Fix #978 i18n not working
1 parent 7ac7997 commit f0e9eb1

File tree

5 files changed

+6
-3
lines changed

5 files changed

+6
-3
lines changed

pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,5 @@
520520
<artifactId>jcefmaven</artifactId>
521521
<version>126.2.0</version>
522522
</dependency>
523-
524523
</dependencies>
525524
</project>

src/main/java/com/ghostchu/peerbanhelper/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class Main {
6060
private static final EventBus eventBus = new EventBus();
6161
@Getter
6262
private static final ReloadManager reloadManager = new ReloadManager();
63-
public static String DEF_LOCALE = Locale.getDefault().toLanguageTag();
63+
public static String DEF_LOCALE = Locale.getDefault().toLanguageTag().toLowerCase(Locale.ROOT).replace("-", "_");
6464
@Getter
6565
private static File dataDirectory;
6666
@Getter

src/main/java/com/ghostchu/peerbanhelper/text/TextManager.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ public static String tlUI(TranslationComponent translationComponent) {
6060
// }
6161

6262
public static String tl(String locale, Lang key, Object... params) {
63+
locale = locale.toLowerCase(Locale.ROOT).replace("-", "_");
6364
return tl(locale, new TranslationComponent(key.getKey(), (Object[]) convert(locale, params)));
6465
}
6566

6667
public static String tl(String locale, TranslationComponent translationComponent) {
67-
locale = locale.toLowerCase(Locale.ROOT);
68+
locale = locale.toLowerCase(Locale.ROOT).replace("-", "_");
6869
YamlConfiguration yamlConfiguration = INSTANCE_HOLDER.languageFilesManager.getDistribution(locale);
6970
if (yamlConfiguration == null) {
7071
yamlConfiguration = INSTANCE_HOLDER.languageFilesManager.getDistribution("en_us");
@@ -146,12 +147,14 @@ public void load() {
146147
Collection<String> pending = getOverrideLocales(languageFilesManager.getDistributions().keySet());
147148
log.debug("Pending: {}", Arrays.toString(pending.toArray()));
148149
pending.forEach(locale -> {
150+
locale = locale.toLowerCase(Locale.ROOT).replace("-", "_");
149151
File file = getOverrideLocaleFile(locale);
150152
if (file.exists()) {
151153
YamlConfiguration configuration = new YamlConfiguration();
152154
try {
153155
configuration.loadFromString(Files.readString(file.toPath(), StandardCharsets.UTF_8));
154156
languageFilesManager.deploy(locale, configuration);
157+
System.out.println("deployed " + locale);
155158
} catch (InvalidConfigurationException | IOException e) {
156159
log.warn("Failed to override translation for {}.", locale, e);
157160
}
@@ -283,6 +286,7 @@ protected Collection<String> getOverrideLocales(@NotNull Collection<String> pool
283286

284287
@NotNull
285288
private File getOverrideLocaleFile(@NotNull String locale) {
289+
locale = locale.toLowerCase(Locale.ROOT).replace("-", "_");
286290
File file;
287291
// bug fixes workaround
288292
file = new File(overrideDirectory, locale + ".yml");

0 commit comments

Comments
 (0)