briosheje

Untitled

Sep 10th, 2018
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Test {
  2.  
  3.     constructor() {
  4.     }
  5.  
  6.     /**
  7.      * Loads translations
  8.      */
  9.     async _loadTranslations() {
  10.         console.log("Loading tanslations");
  11.         let response = await fetch('data.json');
  12.         let json =  await response.json();
  13.         return json;
  14.     }
  15.  
  16.     async translate(key, language) {
  17.       if(!this.translation){
  18.         this.translation = await this._loadTranslations();
  19.        }
  20.        return this.translations[language][key];
  21.     }
  22.  
  23. }
  24.  
  25. (async() => {
  26.     console.log("translation", await (new Test()).translate("MEGA_MENU_CMD","de-DE"));
  27. })();
Advertisement
Add Comment
Please, Sign In to add comment