includes/clientside/static/l10n.js
changeset 582 a38876c0793c
parent 581 5e8fd89c02ea
child 583 c97d5f0d6636
equal deleted inserted replaced
581:5e8fd89c02ea 582:a38876c0793c
     2  * Enano client-side localization library
     2  * Enano client-side localization library
     3  */
     3  */
     4 
     4 
     5 var Language = function(lang_id)
     5 var Language = function(lang_id)
     6 {
     6 {
       
     7   // load the language file
       
     8   load_show_win('strings');
       
     9   var ajax = ajaxMakeXHR();
       
    10   var uri = makeUrlNS('Special', 'LangExportJSON/' + lang_id);
       
    11   ajax.open('GET', uri, false);
       
    12   ajax.send(null);
       
    13   if ( ajax.readyState == 4 && ajax.status == 200 )
       
    14   {
       
    15     eval_global(ajax.responseText);
       
    16   }
       
    17   
     7   if ( typeof(enano_lang) != 'object' )
    18   if ( typeof(enano_lang) != 'object' )
     8     return false;
    19     return false;
     9   if ( typeof(enano_lang[lang_id]) != 'object' )
    20   if ( typeof(enano_lang[lang_id]) != 'object' )
    10     return false;
    21     return false;
    11   this.strings = enano_lang[lang_id];
    22   this.strings = enano_lang[lang_id];
    54   placeholder: true
    65   placeholder: true
    55 };
    66 };
    56 
    67 
    57 var language_onload = function()
    68 var language_onload = function()
    58 {
    69 {
    59   if ( typeof(enano_lang) != 'object' )
       
    60   {
       
    61     language_onload_resched();
       
    62     return true;
       
    63   }
       
    64   if ( !enano_lang[ENANO_LANG_ID] )
       
    65   {
       
    66     language_onload_resched();
       
    67     return true;
       
    68   }
       
    69   $lang = new Language(ENANO_LANG_ID);
    70   $lang = new Language(ENANO_LANG_ID);
    70 }
    71 }
    71 
    72 
    72 // Rescheduler for language onload - allows delaying init if the string list
       
    73 // isn't ready yet
       
    74 function language_onload_resched()
       
    75 {
       
    76   if ( window.console )
       
    77   {
       
    78     // window.console.info('Delaying language init by 0.2s because language_onload decided that enano_lang[ENANO_LANG_ID] isn\'t ready');
       
    79   }
       
    80   setTimeout('language_onload();', 200);
       
    81 }
       
    82 
       
    83 addOnloadHook(language_onload);
    73 addOnloadHook(language_onload);
    84