1/* 2 Document : storm.translations 3 Author : mkr 4 Dependencies : provider.js 5 Description: 6 Adding the functionality to translate all static text in plugins. 7 */ 8 9var storm_translations = { 10 translations : {}, 11 settings : { 12 load: 'static' // static or ajax 13 }, 14 type : '', 15 init : function(type) { 16 storm_translations.type = type; 17 // load files static way 18 if (storm_translations.settings.load == 'static') { 19 // check the language and load the translation file if exists 20 var load_language = true; 21 var file_path = storm.path.translation; 22 // load extended translation file 23 if (storm_translations.type == 'extended') { 24 25 file_path = storm.path.extended_translation; 26 if (!storm.lib.plugin.file_exists(file_path + '/' + storm_translations.get_language() + storm.path.ext_js)) { 27 load_language = false; 28 } 29 } 30 31 if (load_language) { 32 33 head.js(file_path + '/' + storm_translations.get_language() + storm.path.ext_js, function() { 34 35 storm_translations.set(translations); 36 37 if (!storm_translations.type) { 38 storm_translations.init('extended'); 39 return true; 40 } 41 42 // load plugins if loading function exists 43 if(typeof storm.lib.load === 'function') { 44 $(document).trigger('load-provider'); 45 } 46 }); 47 } 48 } else if (storm_translations.settings.load == 'ajax') { 49 // TODO load by Ajax call 50 } 51 }, 52 sprintf : function(format,ele){ 53 for( var i=2; i < ele.length; i++ ) { 54 format = format.replace( /%s/, ele[i] ); 55 } 56 return format; 57 }, 58 set : function(translations) { 59 // merging together original translation file with extended one 60 $.extend(true, storm_translations.translations, translations); 61 }, 62 get : function(plugin, key) { 63 64 // returns translated string or throws error when there is no translation 65 if (storm_translations.translations[plugin][key]) { 66 67 if(arguments.length > 2) { 68 return storm_translations.sprintf(storm_translations.translations[plugin][key], arguments); 69 } else { 70 return storm_translations.translations[plugin][key]; 71 } 72 73 } else { 74 var error = 'NO KEY EXISTS: ' + plugin + '::' + key; 75 s_d.l(error); 76 return error; 77 } 78 }, 79 get_language : function() { 80 // getting page language based on HTML lang attribute 81 return $('html').attr('lang'); 82 } 83};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.