From 3982da5c63bd8a1def243eaebbfd914110084e9b Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 19 Jan 2023 18:53:07 +0000 Subject: [PATCH] Remove old code --- .../common/util/TranslationTools.java | 167 ------------------ 1 file changed, 167 deletions(-) delete mode 100644 RebornCore/src/main/java/reborncore/common/util/TranslationTools.java diff --git a/RebornCore/src/main/java/reborncore/common/util/TranslationTools.java b/RebornCore/src/main/java/reborncore/common/util/TranslationTools.java deleted file mode 100644 index 9a9aa2f26..000000000 --- a/RebornCore/src/main/java/reborncore/common/util/TranslationTools.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * This file is part of RebornCore, licensed under the MIT License (MIT). - * - * Copyright (c) 2021 TeamReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package reborncore.common.util; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.stream.Collectors; - -// Quick too to migrate to the new lang format, and to try and keep as many lang entries as possible -public class TranslationTools { - - // Scanner used for manual matching - private static final Scanner SCANNER = new Scanner(System.in); - - public static void main(String[] args) throws IOException { - Path dir = Paths.get("C:\\Users\\mark\\Desktop\\translations"); - //generateMigrationMap(dir); - migrateMappings(dir); - } - - private static void migrateMappings(Path dir) throws IOException { - final Map keyMap = readJsonFile(dir.resolve("map.json")); - final Map newLang = readJsonFile(dir.resolve("en_us.json")); - - Path outputDir = dir.resolve("out"); - Files.createDirectories(outputDir); - - for (Path path : Files.walk(dir.resolve("old")).collect(Collectors.toList())) { - if (Files.isDirectory(path)) { - continue; - } - Map oldLang = readLangFile(path); - Map output = new HashMap<>(); - - for (Map.Entry entry : oldLang.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (keyMap.containsKey(key)) { - key = keyMap.get(key); - } - if (!newLang.containsKey(key)) { - // Lost key, no point copying them over - continue; - } - output.put(key, value); - } - - - Path outputPath = outputDir.resolve(path.getFileName().toString().toLowerCase().replace(".lang", ".json")); - writeJsonMap(outputPath, output); - } - } - - @SuppressWarnings("unused") - private static void generateMigrationMap(Path dir) throws IOException { - Map oldLang = readLangFile(dir.resolve("en_us.lang")); - Map newLang = readJsonFile(dir.resolve("en_us.json")); - - Map conversion = new HashMap<>(); - - for (Map.Entry entry : oldLang.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - - List newKeys = getKeysByValue(newLang, value); - if (newKeys.size() == 1) { - conversion.put(key, newKeys.get(0)); - } else if (newKeys.size() > 0) { - boolean autoMatched = false; - String[][] autoMatches = new String[][]{{"tile.", "block."}, {"fluid.", "fluid."}}; - for (String[] arr : autoMatches) { - if (key.startsWith(arr[0])) { - for (String newKey : newKeys) { - if (newKey.startsWith(arr[1])) { - autoMatched = true; - conversion.put(key, newKey); - } - } - } - } - if (!autoMatched) { - System.out.println(); - System.out.println(key); - System.out.println(); - for (int i = 0; i < newKeys.size(); i++) { - System.out.printf("%d) %s%n", i, newKeys.get(i)); - } - System.out.print("Input selection:"); - int input = SCANNER.nextInt(); - conversion.put(key, newKeys.get(input)); - System.out.println(); - } - } - } - - writeJsonMap(dir.resolve("map.json"), conversion); - } - - private static Map readJsonFile(Path path) throws IOException { - Type mapType = new TypeToken>() { - }.getType(); - return new Gson().fromJson(Files.readString(path), mapType); - } - - private static Map readLangFile(Path path) throws IOException { - List lines = Files.lines(path).collect(Collectors.toList()); - Map map = new HashMap<>(); - for (String line : lines) { - line = line.trim(); - if (line.isEmpty() || line.startsWith("#")) { - continue; - } - String[] split = line.split("="); - if (split.length != 2) { - throw new UnsupportedOperationException(); - } - map.put(split[0], split[1]); - } - return map; - } - - private static void writeJsonMap(Path path, Map map) throws IOException { - Files.deleteIfExists(path); - String json = new Gson().toJson(map); - Files.write(path, json.getBytes()); - } - - private static List getKeysByValue(Map map, E value) { - List keys = new ArrayList<>(); - for (Map.Entry entry : map.entrySet()) { - if (Objects.equals(value, entry.getValue())) { - keys.add(entry.getKey()); - } - } - return keys; - } - -}