Reputation: 7891
Found this script on JSFiddle that would switch between languages. The problem is. When I type in the text with <br>
it displays the breaks.
How can I get it to actually break the text?
Also, how can I get it to choose a default language? So every time you reload the page it will be that language that is selected. Otherwise, nothing is displayed until you select the language manually.
Also, I would highly appreciate it, if you can recommend other such scripts that are better then this one.
function getLanguageResources(){
var fr = new Array(); var en = new Array();
fr['settings'] = "paramètres"; en['settings'] = "settings";
fr['default_feed'] = "Flux par défaut"; en['default_feed'] = "Default feed";
fr['hidden'] = "Masquer"; en['hidden'] = " Hidden";
fr['save_settings'] = "Enregistrer les paramètres"; en['save_settings'] = "Save settings";
var resources = new Array();
resources['fr'] = fr;
resources['en'] = en;
return resources;
}
function changeLanguage(lang){
var langResources = getLanguageResources()[lang];
$("span[name='lbl']").each(function(i, elt){
$(elt).text(langResources[$(elt).attr("caption")]);
});
}
$(document).ready(function() {
$("input[name='radio-language']").click(function(){
changeLanguage($(this).val());
});
});
Thanks.
Upvotes: 0
Views: 102
Reputation: 20518
To break the text, apply your string as HTML instead of text:
$(elt).html(langResources[$(elt).attr("caption")]);
To set a default language, set the checked
attribute on the appropriate radio button and simulate a click
event in your $(document).ready
callback:
$("#radioEnglish").attr("checked", true).trigger("click");
Upvotes: 1