forked from lishid/OpenInv
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add fallthrough to "parent" language * I am aware that the "correct" parent for Portuguese is likely `pt_pt`, but as no one has submitted it, welcome to Brazil. * Use English for lowercasing locale name * Fixes potential issues locating translations for certain languages on systems in other languages * Migrate locales to "locale" subdirectory to reduce clutter * Fix container settings getting clobbered/not suggested correctly/not editable * This was due to a quirk of the YAML parser - OpenInv was looking for `'on'` and `'off'` but translation files provided `'true'` and `'false'` due to the paths being interpreted as truthy. The built-in translations have had their paths quoted to fix this. You will need to manually relocate these if you have custom translations.
- Loading branch information
Showing
9 changed files
with
174 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
plugin/src/main/java/com/lishid/openinv/util/LangMigrator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.lishid.openinv.util; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.FileAlreadyExistsException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class LangMigrator { | ||
|
||
private final @NotNull Path oldFolder; | ||
private final @NotNull Path newFolder; | ||
private final @NotNull Logger logger; | ||
|
||
public LangMigrator(@NotNull Path oldFolder, @NotNull Path newFolder, @NotNull Logger logger) { | ||
this.oldFolder = oldFolder; | ||
this.newFolder = newFolder; | ||
this.logger = logger; | ||
} | ||
|
||
public void migrate() { | ||
if (!Files.exists(oldFolder.resolve("en_us.yml"))) { | ||
// Probably already migrated. | ||
return; | ||
} | ||
|
||
logger.info(() -> String.format("[LanguageManager] Migrating language files to %s", newFolder)); | ||
|
||
if (!Files.exists(newFolder)) { | ||
try { | ||
Files.createDirectories(newFolder); | ||
} catch (IOException e) { | ||
logger.log(Level.WARNING, "Unable to create language subdirectory!", e); | ||
} | ||
} | ||
|
||
try (DirectoryStream<Path> files = Files.newDirectoryStream(oldFolder)) { | ||
files.forEach(path -> { | ||
if (path == null) { | ||
return; | ||
} | ||
|
||
String fileName = path.getFileName().toString(); | ||
|
||
if (fileName.startsWith("config") || !fileName.endsWith(".yml")) { | ||
return; | ||
} | ||
|
||
// Migrate certain files to be parent languages. | ||
fileName = switch (fileName) { | ||
case "en_us.yml" -> "en.yml"; | ||
case "de_de.yml" -> "de.yml"; | ||
case "es_es.yml" -> "es.yml"; | ||
case "pt_br.yml" -> "pt.yml"; | ||
default -> fileName; | ||
}; | ||
|
||
try { | ||
Files.copy(path, newFolder.resolve(fileName)); | ||
Files.delete(path); | ||
} catch (FileAlreadyExistsException e1) { | ||
// File already migrated? | ||
try { | ||
Files.copy(path, newFolder.resolve("old_" + fileName)); | ||
Files.delete(path); | ||
} catch (IOException e2) { | ||
// If it fails again, just re-throw. | ||
throw new UncheckedIOException(e2); | ||
} | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
}); | ||
} catch (UncheckedIOException e) { | ||
logger.log(Level.WARNING, "Unable to migrate languages to subdirectory!", e.getCause()); | ||
} catch (IOException e) { | ||
logger.log(Level.WARNING, "Unable to migrate languages to subdirectory!", e); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters