diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index ffd43031..c2feaa96 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -42,7 +42,7 @@ class App { // The locale should be specified in ISO 639-1 format: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes // "system" is a special case that will use the system locale public static var locale = "system"; - static var translations: Map = []; + public static var translations: Map = []; public static var isDragging = false; public static var isResizing = false; public static var dragMaterial: MaterialSlot = null; @@ -231,25 +231,6 @@ class App { else System.stop(); } - // Localizes a string with the given placeholders replaced (format is `{placeholderName}`). - // If the string isn't available in the translation, this method will return the source English string. - public static function tr(id: String, ?vars: Map): String { - var translation = id; - - // English is the source language - if (locale != "en" && translations != null && translations.exists(id)) { - translation = translations[id]; - } - - if (vars != null) { - for (key => value in vars) { - translation = translation.replace('{$key}', Std.string(value)); - } - } - - return translation; - } - public static function w(): Int { // Draw material preview if (UISidebar.inst != null && UISidebar.inst.materialPreview) { diff --git a/Sources/arm/Locale.hx b/Sources/arm/Locale.hx deleted file mode 100644 index 4aa4476b..00000000 --- a/Sources/arm/Locale.hx +++ /dev/null @@ -1,16 +0,0 @@ -package arm; - -class Locale { - - // Localize a string with the given placeholders replaced (format is `{placeholderName}`). - // TODO: Implement localization support. - public static function tr(id: String, ?vars: Map): String { - if (vars != null) { - for (key => value in vars) { - id = id.replace('{$key}', Std.string(value)); - } - } - - return id; - } -} diff --git a/Sources/arm/Translator.hx b/Sources/arm/Translator.hx new file mode 100644 index 00000000..def20344 --- /dev/null +++ b/Sources/arm/Translator.hx @@ -0,0 +1,23 @@ +package arm; + +class Translator { + + // Localizes a string with the given placeholders replaced (format is `{placeholderName}`). + // If the string isn't available in the translation, this method will return the source English string. + public static function tr(id: String, ?vars: Map): String { + var translation = id; + + // English is the source language + if (App.locale != "en" && App.translations != null && App.translations.exists(id)) { + translation = App.translations[id]; + } + + if (vars != null) { + for (key => value in vars) { + translation = translation.replace('{$key}', Std.string(value)); + } + } + + return translation; + } +} diff --git a/Sources/arm/ui/BoxPreferences.hx b/Sources/arm/ui/BoxPreferences.hx index 7ab11e11..f92156b8 100644 --- a/Sources/arm/ui/BoxPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -32,7 +32,7 @@ class BoxPreferences { Config.raw.locale = localeCode; Config.save(); App.loadTranslations(localeCode); - UITrait.inst.tagUIRedraw(); + UISidebar.inst.tagUIRedraw(); } var hscale = Id.handle({value: Config.raw.window_scale}); diff --git a/Sources/import.hx b/Sources/import.hx index 9be6e585..bf5e345f 100644 --- a/Sources/import.hx +++ b/Sources/import.hx @@ -2,7 +2,7 @@ #if (!macro) -import arm.Locale.tr; +import arm.Translator.tr; using StringTools; #end