author | Dan |
Wed, 15 Apr 2009 19:44:47 -0400 | |
changeset 915 | 91f4da84966f |
parent 780 | f65e35566b63 |
child 1196 | 704ba4b9819b |
permissions | -rw-r--r-- |
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
1 |
/* |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
2 |
* Enano client-side localization library |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
3 |
*/ |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
4 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
5 |
var Language = function(lang_id) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
6 |
{ |
583 | 7 |
var have_lang = false; |
8 |
||
9 |
if ( typeof(enano_lang) == 'object' ) |
|
10 |
{ |
|
11 |
if ( typeof(enano_lang[lang_id]) == 'object' ) |
|
12 |
{ |
|
13 |
have_lang = true; |
|
14 |
} |
|
15 |
} |
|
16 |
if ( !have_lang ) |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
17 |
{ |
583 | 18 |
// load the language file |
19 |
load_show_win('strings'); |
|
588
20484deb89cd
Upgraded TinyMCE to 3.1.0.1. Ported a couple special pages to the componentized JS system.
Dan
parents:
586
diff
changeset
|
20 |
console.info('Loading language ' + lang_id + ' via AJAX synchronous request'); |
583 | 21 |
var ajax = ajaxMakeXHR(); |
22 |
var uri = makeUrlNS('Special', 'LangExportJSON/' + lang_id); |
|
23 |
ajax.open('GET', uri, false); |
|
24 |
ajax.send(null); |
|
25 |
if ( ajax.readyState == 4 && ajax.status == 200 ) |
|
26 |
{ |
|
27 |
eval_global(ajax.responseText); |
|
28 |
} |
|
586
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents:
583
diff
changeset
|
29 |
load_hide_win(); |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
30 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
581
diff
changeset
|
31 |
|
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
32 |
if ( typeof(enano_lang) != 'object' ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
33 |
return false; |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
34 |
if ( typeof(enano_lang[lang_id]) != 'object' ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
35 |
return false; |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
36 |
this.strings = enano_lang[lang_id]; |
391
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
parents:
387
diff
changeset
|
37 |
this.lang_id = lang_id; |
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
568
diff
changeset
|
38 |
this.placeholder = false; |
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
39 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
40 |
this.get = function(string_id, subst) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
41 |
{ |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
42 |
var catname = string_id.substr(0, string_id.indexOf('_')); |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
43 |
var string_name = string_id.substr(string_id.indexOf('_') + 1); |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
44 |
if ( typeof(this.strings[catname]) != 'object' ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
45 |
return string_id; |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
46 |
if ( typeof(this.strings[catname][string_name]) != 'string' ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
47 |
return string_id; |
387
92664d2efab8
Rebranded source code as 1.1.1; added TinyMCE ACL rule as per Vadi's request: http://forum.enanocms.org/viewtopic.php?f=7&t=54
Dan
parents:
335
diff
changeset
|
48 |
return this.perform_subst(this.strings[catname][string_name], subst); |
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
49 |
} |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
50 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
51 |
this.perform_subst = function(str, subst) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
52 |
{ |
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
53 |
var this_regex = /%this\.([a-z0-9_]+)%/; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
54 |
var match; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
55 |
while ( str.match(this_regex) ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
56 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
57 |
match = str.match(this_regex); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
58 |
str = str.replace(match[0], this.get(match[1])); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
59 |
} |
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
60 |
// hackish workaround for %config.*% |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
61 |
str = str.replace(/%config\.([a-z0-9_]+)%/g, '%$1%'); |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
62 |
if ( typeof(subst) == 'object' ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
63 |
{ |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
64 |
for ( var i in subst ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
65 |
{ |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
66 |
if ( !i.match(/^([a-z0-9_]+)$/) ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
67 |
continue; |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
68 |
var regex = new RegExp('%' + i + '%', 'g'); |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
69 |
str = str.replace(regex, subst[i]); |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
70 |
} |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
71 |
} |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
72 |
return str; |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
73 |
} |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
74 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
75 |
} |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
76 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
77 |
var language_onload = function() |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
78 |
{ |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
diff
changeset
|
79 |
$lang = new Language(ENANO_LANG_ID); |
461 | 80 |
} |
81 |
||
780
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
82 |
var $lang = { |
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
83 |
get: function(t, s) { |
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
84 |
language_onload(); |
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
85 |
return $lang.get(t, s); |
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
86 |
}, |
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
87 |
placeholder: true |
f65e35566b63
A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents:
588
diff
changeset
|
88 |
}; |