Thus far I haven't seen any information on MVC support for Globalization and Localization.
But from my research, ASP.NET 2.0 handles it via any tag that has runat=server, something that MVC hasn't got.
I have my ideas about how it might be done, but I will leave the question open-ended, hear what Microsoft has to say.
No doubt ScottGu will eventually do an awesome post on it, but I can't really wait that long, my employer is on the eve of embarking on a web application with globalization concerns, and we are also assessing the MVC framework.
The MVC framework supports using the existing ASP.NET .ASPX, .ASCX, and .Master markup files as "view templates" (meaning you can easily use existing ASP.NET features like nested master pages, <%= %> snippets, declarative server controls, templates, data-binding,
localization, etc).
So lets try a traditional way ... :-
a) Create a view -> \Views\Index.aspx
b) Create a resource folder and files:-
\Views\App_LocalResources\Index.aspx.resx <-- default or culture neutral
\Views\App_LocalResources\Index.aspx.fr.resx <-- French
\Views\App_LocalResources\Index.aspx.de.resx <-- german
c) wireup some text / html to be 'localized' :-
<asp:Literal runat="server" text="<%$ Resources:SomeKeyInTheResourceFile %>" />
.. and that works :)
To test this out, you can make the page AUTO DETECT the browser 'language' setting, and then play around with the browsers language list preferences.
That said, i was hoping to do this without the use of an asp:control ... like..
<span><%$ Resources:SomeKeyInTheResourceFile %></span> <-- insert localized content.
... but that doesn't work .. and i have no idea how to do it without an asp.control :(
:: Never underestimate the predictability of stupidity ::
I am using the simpler approach of global resources as mentioned above and it works like a charm. There is also a database provider that makes things even easier. It caches on load -up so the speed is the same. Here is that project if you want to check it
out. : http://www.west-wind.com/tools/wwDbResourceProvider/docs/ It is an older version but still works without too much tweaking.
That said, i was hoping to do this without the use of an asp:control ... like..
<span><%$ Resources:SomeKeyInTheResourceFile %></span> <-- insert localized content.
... but that doesn't work .. and i have no idea how to do it without an asp.control :(
Based on this thread, I decided to go ahead and try to use the West Wind provider, but so far haven't been able to get it working... I just get an empty admin tool, even when I add records to the Localizations table manually.
Would you mind detailing how you managed to get it to work, including the LocalizationAdmin tool?
ok, my question is quite simple. How do I localize a HtmlHelper in ASP.NET MVC.
I have a Html.TextBox("UnitPrice"), and I want it to show the price with a comma for de decimal separator instead of a dot.
Example: 16,00 instead of 16.00
jbgoldcoast
Member
22 Points
10 Posts
MVC & Globalization / Localization
Jan 16, 2008 11:41 PM|LINK
Thus far I haven't seen any information on MVC support for Globalization and Localization.
But from my research, ASP.NET 2.0 handles it via any tag that has runat=server, something that MVC hasn't got.
I have my ideas about how it might be done, but I will leave the question open-ended, hear what Microsoft has to say.
No doubt ScottGu will eventually do an awesome post on it, but I can't really wait that long, my employer is on the eve of embarking on a web application with globalization concerns, and we are also assessing the MVC framework.
MVC localization Globalization
dimi3
Member
318 Points
166 Posts
Re: MVC & Globalization / Localization
Jan 17, 2008 05:42 AM|LINK
I am also deeply interested in that subject and hope to see something clean about it soon.
pure.krome
Member
532 Points
349 Posts
Re: MVC & Globalization / Localization
Feb 14, 2008 11:01 PM|LINK
Yep - same here. In fact, it's a must, for converting our website.
So, lets try and nut this out.
Here is the asp.net official quickstart tutorial for localization: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/default.aspx
Supposedly, ScottGu says that localization should work Out Of the Box with the current release of the ASP.NET MVC
So lets try a traditional way ... :-
a) Create a view -> \Views\Index.aspxb) Create a resource folder and files:-
\Views\App_LocalResources\Index.aspx.resx <-- default or culture neutral
\Views\App_LocalResources\Index.aspx.fr.resx <-- French
\Views\App_LocalResources\Index.aspx.de.resx <-- german
c) wireup some text / html to be 'localized' :-
<asp:Literal runat="server" text="<%$ Resources:SomeKeyInTheResourceFile %>" />
.. and that works :)
To test this out, you can make the page AUTO DETECT the browser 'language' setting, and then play around with the browsers language list preferences.
That said, i was hoping to do this without the use of an asp:control ... like..
<span><%$ Resources:SomeKeyInTheResourceFile %></span> <-- insert localized content.
... but that doesn't work .. and i have no idea how to do it without an asp.control :(
wcpierce
Member
47 Points
16 Posts
Re: MVC & Globalization / Localization
Feb 15, 2008 04:24 AM|LINK
Here is an approach that is a little simpler.
http://forums.asp.net/p/1198465/2079186.aspx#2079186
http://blechie.com/wpierce/
mrfleck
Member
164 Points
109 Posts
Re: MVC & Globalization / Localization
Feb 15, 2008 06:47 AM|LINK
I am using the simpler approach of global resources as mentioned above and it works like a charm. There is also a database provider that makes things even easier. It caches on load -up so the speed is the same. Here is that project if you want to check it out. : http://www.west-wind.com/tools/wwDbResourceProvider/docs/ It is an older version but still works without too much tweaking.
developmenta...
Member
115 Points
65 Posts
Re: MVC & Globalization / Localization
Feb 15, 2008 02:03 PM|LINK
Here's what I've been doing and it works great:
pure.krome
Member
532 Points
349 Posts
Re: MVC & Globalization / Localization
Feb 16, 2008 01:23 AM|LINK
sweet dude :) i have to give that a go, next week at work.
uber cheers!
3 cheers to these MVC forums :)
timstewart
Member
2 Points
1 Post
Re: MVC & Globalization / Localization
Aug 28, 2008 03:52 PM|LINK
Based on this thread, I decided to go ahead and try to use the West Wind provider, but so far haven't been able to get it working... I just get an empty admin tool, even when I add records to the Localizations table manually.
Would you mind detailing how you managed to get it to work, including the LocalizationAdmin tool?
TIA,
-= Tim
fredgcosta
Member
2 Points
1 Post
Re: MVC & Globalization / Localization
Oct 05, 2008 12:56 AM|LINK
ok, my question is quite simple. How do I localize a HtmlHelper in ASP.NET MVC.
I have a Html.TextBox("UnitPrice"), and I want it to show the price with a comma for de decimal separator instead of a dot.
Example: 16,00 instead of 16.00
htmlhelper i18n Globalization localisation
slasi.net
Member
135 Points
93 Posts
Re: MVC & Globalization / Localization
May 19, 2009 10:00 PM|LINK
Hi,
i am trying to use this:
view/Account/App_LocalResources/PrivateDetails.aspx.resx
there i have 1 key:
Name: label_FirstName value: First Name
in the view/PrivateDetails.aspx
i use:
<span><%= Resources.PrivateDetails.label_FirstName %></span>
i get an error:
The type or namespace name 'PrivateDetails' does not exist in the namespace 'System.Resources' (are you missing an assembly reference?)
any idea what need to be done ?
Thanks
Ori