translations fully working (text only)
next step is adding the assets part
This commit is contained in:
@@ -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<String> = [];
|
||||
#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<String, String>
|
||||
{
|
||||
#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) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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<String> = 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",
|
||||
|
||||
Reference in New Issue
Block a user