|
@@ -0,0 +1,60 @@
|
|
|
+if(lan !== undefined){
|
|
|
+ var syslang = navigator.language;
|
|
|
+ var ContainsNonTagElement = [];
|
|
|
+ $.each($("*"), function( index, value ) {
|
|
|
+ //to check if the element was the script or style, if it is script or style then skip it
|
|
|
+ if($(value)[0].tagName.toUpperCase() !== "SCRIPT" && $(value)[0].tagName.toUpperCase() !== "STYLE"){
|
|
|
+ //if the element doesn't contains any children element
|
|
|
+ if(!$(value).children().length){
|
|
|
+ //check if it is textbox, if true then show placeholder
|
|
|
+ if($(value).attr("placeholder") !== undefined){
|
|
|
+ var t = $(value).attr("placeholder").trim();
|
|
|
+ if(t.length > 0){
|
|
|
+ $(value).attr("placeholder",intl_convert(syslang,t));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //if it is normal text, display the text
|
|
|
+ if($(value).html() !== undefined){
|
|
|
+ var t = $(value).text().trim();
|
|
|
+ if(t.length > 0){
|
|
|
+ $(value).html($(value).html().replace(t,intl_convert(syslang,t)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //if it still contains some child element, then try to remove all element and check if there contains any text
|
|
|
+ //if we find any, then store it and process it later.
|
|
|
+ var t = $(value).clone().children().remove().end().text().trim();
|
|
|
+ if(t.length > 0){
|
|
|
+ ContainsNonTagElement.push($(value))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $.each(ContainsNonTagElement, function( index, value ) {
|
|
|
+ var t = $(value).clone().children().remove().end().text().trim();
|
|
|
+ if(t.length > 0){
|
|
|
+ $(value).html($(value).html().replace(t,intl_convert(syslang,t)));
|
|
|
+ }
|
|
|
+ });
|
|
|
+}else{
|
|
|
+ throw "No language file was find, include variable lan and try again.";
|
|
|
+}
|
|
|
+
|
|
|
+function intl_convert(lang,t){
|
|
|
+ if(lan == undefined){
|
|
|
+ throw "No language file was find, include variable lan and try again.";
|
|
|
+ }
|
|
|
+ var r = new RegExp("[0-9,.]+");
|
|
|
+ var num_part = t.match(r);
|
|
|
+ if(num_part == null){
|
|
|
+ num_part = "";
|
|
|
+ }
|
|
|
+ var text_part = t.replace(r,"");
|
|
|
+ if(lan[lang][t.replace(r,"%n")] !== undefined){
|
|
|
+ var convertedtext = lan[lang][t.replace(r,"%n")].replace("%n",num_part);
|
|
|
+ }else{
|
|
|
+ var convertedtext = t;
|
|
|
+ }
|
|
|
+ console.log("Number part: " + num_part + "\nText part: " + text_part + "\nInput text: " + t + "\nProcessed text: " + t.replace(r,"%n") + "\nConverted: " + convertedtext);
|
|
|
+ return convertedtext;
|
|
|
+}
|