From 2ba7aaf0e987fd24578609bb9684ced40fb77c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Tue, 2 Apr 2024 04:37:08 +0200 Subject: [PATCH] translations fully working (text only) next step is adding the assets part --- .../funkin/backend/utils/TranslationsUtil.hx | 25 ++++++++----------- source/funkin/menus/ui/Alphabet.hx | 4 +-- .../funkin/options/categories/MiscOptions.hx | 12 ++++++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/funkin/backend/utils/TranslationsUtil.hx b/source/funkin/backend/utils/TranslationsUtil.hx index e6d3e403..a2c6f40e 100644 --- a/source/funkin/backend/utils/TranslationsUtil.hx +++ b/source/funkin/backend/utils/TranslationsUtil.hx @@ -22,7 +22,7 @@ class TranslationsUtil /** * The default language used inside of the source code. */ - public static var DEFAULT_LANGUAGE:String = 'English'; // no inline so psycopathic mods can edit it - Nex + public static var DEFAULT_LANGUAGE:String = 'en/English'; // no inline so psycopathic mods can edit it - Nex /** * Returns the current language. @@ -48,7 +48,7 @@ class TranslationsUtil * If `name` is `null`, it's gonna use the current language. */ public static function setTransl(?name:String) - trace(transMap = loadLanguage(name == null ? get_curLanguage() : name)); + transMap = loadLanguage(name == null ? get_curLanguage() : name); /** * This is for checking a translation, `defString` it's just the string that gets returned just in case it won't find the translation OR the current language selected is ``DEFAULT_LANGUAGE``. @@ -71,32 +71,29 @@ class TranslationsUtil { var translations:Array = []; #if TRANSLATIONS_SUPPORT - // to finish once done with the lib thing - Nex - for(l in Assets.list()) { - var d = Path.directory(l); - if(d.startsWith(Paths.translationsMain(''))) { - d = (d.replace(Paths.translationsMain(''), "").split("/"))[0]; - if(!translations.contains(d)) translations.push(d); - } - } + var main:String = Paths.translationsMain(''); + for(l in Paths.assetsTree.getFolders(main)) for(f in Paths.assetsTree.getFiles(main + l)) + if(Path.extension('$l/$f') == "xml") translations.push(Path.withoutExtension('$l/$f')); #end return translations; } /** - * Returns a map of translations based on its main.xml. + * Returns a map of translations based on its XML. */ public static function loadLanguage(name:String):Map { #if TRANSLATIONS_SUPPORT - var path:String = Paths.translationsMain('$name/main.xml'); + var path:String = Paths.translationsMain(name); + if(!path.endsWith(".xml")) path += ".xml"; if (!Assets.exists(path, TEXT)) return []; var xml:Access = null; try xml = new Access(Xml.parse(Assets.getText(path))) catch(e) { - FlxG.log.error('Error while parsing main.xml: ${Std.string(e)}'); - throw new Exception('Error while parsing main.xml: ${Std.string(e)}'); + var msg:String = 'Error while parsing ${Path.withoutDirectory(name)}.xml: ${Std.string(e)}'; + FlxG.log.error(msg); + throw new Exception(msg); } if (xml == null) return []; if (!xml.hasNode.translations) { diff --git a/source/funkin/menus/ui/Alphabet.hx b/source/funkin/menus/ui/Alphabet.hx index d4c3db47..e8c01f09 100644 --- a/source/funkin/menus/ui/Alphabet.hx +++ b/source/funkin/menus/ui/Alphabet.hx @@ -77,11 +77,11 @@ class Alphabet extends FlxSpriteGroup trace(e.details()); } } - public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false) + public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false, ?transID:String) { super(x, y); - _finalText = this.text = text; + _finalText = this.text = TranslationsUtil.checkTransl(text, transID); isBold = bold; var alphabetPath = Paths.xml("alphabet"); diff --git a/source/funkin/options/categories/MiscOptions.hx b/source/funkin/options/categories/MiscOptions.hx index 28981b99..3b4fa5e3 100644 --- a/source/funkin/options/categories/MiscOptions.hx +++ b/source/funkin/options/categories/MiscOptions.hx @@ -5,11 +5,17 @@ class MiscOptions extends OptionsScreen { public override function new() { super("Miscellaneous", "Use this menu to reset save data or engine settings."); var lanArray:Array = TranslationsUtil.translList(); - lanArray.push(TranslationsUtil.DEFAULT_LANGUAGE); + if(!lanArray.contains(TranslationsUtil.DEFAULT_LANGUAGE)) lanArray.push(TranslationsUtil.DEFAULT_LANGUAGE); add(new ArrayOption( "Language", - 'The language the Engine currently uses (the default one is ${TranslationsUtil.DEFAULT_LANGUAGE}).', - lanArray, lanArray, "language", function(lan:String) TranslationsUtil.setTransl(lan))); + 'The language that the engine currently uses (the default one is ${TranslationsUtil.DEFAULT_LANGUAGE}).', + lanArray, [for(lan in lanArray) lan.split("/").last()], "language", + function(path:String) { + TranslationsUtil.setTransl(path); + parent.remove(this); + this.clear(); + parent.add(new MiscOptions()); + })); #if UPDATE_CHECKING add(new Checkbox( "Enable Nightly Updates",