www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

locale.js (1035B)


      1 // Available language packs
      2 var locales = [
      3 	'ar',
      4 	'bg_BG',
      5 	'ca',
      6 	'cs_CZ',
      7 	'da',
      8 	'de',
      9 	'el',
     10 	'es',
     11 	'et',
     12 	'eu',
     13 	'fa_IR',
     14 	'fi',
     15 	'fr_FR',
     16 	'gl',
     17 	'he_IL',
     18 	'hr',
     19 	'hu_HU',
     20 	'id',
     21 	'is_IS',
     22 	'it',
     23 	'ja',
     24 	'km_KH',
     25 	'ko_KR',
     26 	'lt',
     27 	'nb_NO',
     28 	'nl',
     29 	'pl',
     30 	'pt_BR',
     31 	'pt_PT',
     32 	'ro',
     33 	'ru',
     34 	'sk',
     35 	'sl_SI',
     36 	'sv_SE',
     37 	'th_TH',
     38 	'tr_TR',
     39 	'uk',
     40 	'vi_VN',
     41 	'zh_CN',
     42 	'zh_TW'
     43 ];
     44 
     45 function setLocale(editor) {
     46 	var locale = 'en';
     47 	
     48 	var matches = window.location.href.match(/locale=([^&]+)/);
     49 	if (matches) {
     50 		let code = matches[1].replace('-', '_');
     51 		// Exact match
     52 		if (locales.includes(code)) {
     53 			locale = code;
     54 		}
     55 		else {
     56 			let prefix = code.substr(0, 2);
     57 			// Match on first two characters, exact
     58 			if (locales.includes(prefix)) {
     59 				locale = prefix;
     60 			}
     61 			// Match on first two characters with additional country code (e.g., 'fa' -> 'fa_IR')
     62 			else {
     63 				for (let l of locales) {
     64 					if (l.substr(0, 2) == prefix) {
     65 						locale = l;
     66 						break;
     67 					}
     68 				}
     69 			}
     70 		}
     71 	}
     72 	
     73 	editor.settings.language = locale;
     74 }