Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 12, 2012 11:31 AM by drilli
Apr 10, 2012 07:29 AM|LINK
I am trying to internationalize my web application wich I developed in MVC 3.0.
I can read my values in .resx files from cshtml, but how can I read these values(in .resx files) from my .js files.
Is there any way to serialize or convert .resx files in JSON objects(in controllers in server side) and return that object.After that in this object I can read all ky/value pairs wothout any problem.
Is this possible or do you know any better solution of this problem.
Thank You for reading this question and for everyone who can help me.
Apr 10, 2012 08:50 AM|LINK
You can make localized version of the js file
Apr 10, 2012 11:24 AM|LINK
Explain me in more dtails please, if you can :)
Apr 12, 2012 03:55 AM|LINK
var globalResource = '<%= Resources.YourClass.YourResourceKey %>';
to access the Global Resources (/App_GlobalResources). Or
var localResource = '<%= GetLocalResourceObject("LocalResourceKey").ToString() %>';
to access the Local resources (/App_LocalResources relative to the page position).
You could also look at this tutorials.
Hope this helpful
Apr 12, 2012 07:16 AM|LINK
I read before this tutorial and all microsoft1s tutorials but when they want to use .resx files in .js files then they use JQuery.
I want to do the same thing, but without JQuery.
Is this possible?
Apr 12, 2012 08:18 AM|LINK
I guess you could
- pput a hidden field on the view with the culture.
In the separate js file you could do a json (or ajax call) to get the translations for the culture.
- Have seperate js files for each language with hardcoded strings and couple the right one to the view when rendering the view
Maybe other solutions ...
Apr 12, 2012 09:11 AM|LINK
well I understand it partially. As I could understand I have to:
1.Make seperate js files for every language for example: en.js, en-us.js fr-FR.js, etc, with all key.value pairs for every language.
2. then I shopuld use these files in all other js files in my application.
but I didn`t understand that part "In the separate js file you could do a json (or ajax call) to get the translations for the culture."
Why should I do that JSON call ?
I am sorry but as you can see I don`t have it all clear.
in these js files shold I have JSON objects like this for example:
'en/US':'Are you sure?',
'fr/FR':'Est-ce que vous est certain?',
Thank You indeed for reading and trying to help me.
P.S. I am using asp.net MVC 3
Apr 12, 2012 09:25 AM|LINK
You don't have to do both.
It's create separate js files for each language
One js file in which you get translations with json call.
Apr 12, 2012 10:49 AM|LINK
aha now I understand how to create files and inside them how to create JSON objects.
Thank You for your patient.I really appreciate your help.
Apr 12, 2012 11:22 AM|LINK
Correct. it was just 2 different approaches. You don't need ajax call if you don't need them.