Skip to content

Commit

Permalink
merge custom locales instead of overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
rymiel committed Jan 30, 2024
1 parent 47951d7 commit 8b9a193
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions common/src/main/java/org/popcraft/bolt/lang/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void loadAllTranslations(final Path directory, final String prefer
try (final FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
Stream<Path> files = Files.list(fileSystem.getPath("lang/"))) {
files.forEach(path -> {
if (!path.toString().endsWith(".properties")) {
if (!path.toString().toLowerCase().endsWith(".properties")) {
return;
}

Expand All @@ -97,11 +97,18 @@ public static void loadAllTranslations(final Path directory, final String prefer
e.printStackTrace();
}

// Load user-defined localization files. This is done after, so it overrides any built-in translations.
try (Stream<Path> files = Files.list(directory).filter((name) -> name.toString().toLowerCase().endsWith(".properties"))) {
// Load user-defined localization files.
try (Stream<Path> files = Files.list(directory)) {
files.forEach(path -> {
if (!path.toString().toLowerCase().endsWith(".properties")) {
return;
}

final Locale locale = parseLocale(path.getFileName().toString().split("\\.", 2)[0]);
final Properties properties = loadTranslationFromFile(path);
// If a default locale exists for this language, load it as a base. This allows any translation keys
// that do not have a custom translation set to still fall through to the built-in translation.
final Properties properties = languages.getOrDefault(locale, new Properties());
properties.putAll(loadTranslationFromFile(path));
languages.put(locale, properties);
});
} catch (IOException e) {
Expand Down

0 comments on commit 8b9a193

Please sign in to comment.