What is the recommended way to enable multi-language support for display text in Javascript

Several times I had to support several languages ​​when creating websites, but I have not yet come up with a good way to transfer language strings from server to client so that they can be used in Javascript for dialogs, messages, etc.

What are your recommendations or experiences?

EDIT: I tend to create javascript language files on the fly and would appreciate it if anyone knows third-party libraries that can do this.

+5
source share
5 answers

, , :

st/js/messages-ru.js:

hello = ""
bye = ""

st/js/messages-en.js:

hello = "Hello!"
bye = "Good bye!"

, js.

+2

javascript . JavaScript javascript, . javascripts.

+1

JavaScript, , :

<script type="text/javascript">
    var dialogl10n = {
        caption: '<%= Resources.GetString(x => x.DialogCaption) %>',
        okButton: '<%= SharedResources.GetTerm(x => x.Ok) %>'
        cancelButton: '<%= SharedResources.GetTerm(x => x.Cancel) %>'
    };
</script>

javascript:

Foo.Bar.doSomething = function(l10n) {
    alert(l1n0.caption);
}

, JSON:

onClick='Foo.Bar.doSomething(<%= Resources.GetPackageAsJson(); %>);'

, .

+1

. , js , , uk js uk.js, fr fr.js .

0

ASP.NET AJAX, ScriptManager javascript .resx CultureInfo, . . MSDN .

0

All Articles