[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


ASP.NET to handle multiple languages

Posted on 2014-08-08
Medium Priority
Last Modified: 2014-08-14
I have an ASP.NET project with multiple user controls. The controls use English at the moment and I want them to be reworked to handle multiple languages

When I started my project, I hard coded text in user controls and initially decided that I would make different versions  of the project in different languages but I have changed my mind and I now want to use localization.

I need to create a BasePage to handle the language functionality.

I have already added the resource file. I need the resource files populated and to also have the acsx files changed to function with the populated resource files (English only for now).
Question by:Idarac
  • 4
  • 3
LVL 34

Expert Comment

by:Paul MacDonald
ID: 40249808
...is there a question?

Author Comment

ID: 40249815
Yes how do I about adding the localization to pick up multi languages?
LVL 36

Expert Comment

by:Miguel Oz
ID: 40250065
have you read this walkthrough?
First you need to create not only the English resource file but your supported languages files as well. See section "To create a resource file".
Secondly, you need to use the resource strings (surfaced as properties) from your resource class as shown in section "To add a Label control to the page". Notice that you can assign the string in either the mark-up or code behind.
Lastly, test it you could change your preferred language setting in your browser.
Note: You will require translators to fill up the resource files for other languages. automatic translators are not that good especially for business words/sentences.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40250540
Can you tell me the difference between implicit and explicit ?
LVL 36

Expert Comment

by:Miguel Oz
ID: 40251393
Implicit localization
Create one resource file per page per language.
Specify that control properties should automatically be read from a resource file but you do not need to explicitly specify which properties are localized: Set the "control.property" item to localize in resource file.

Explicit localization
Create one resource file per site per language.
Specify which properties are localized: Set the property in code behind or mark-up with the associated resource value.

My preference is explicit because it gives you:
Direct control over which property is set.
the opportunity to encode the text before setting the property. (Far too many times I was caught with special characters that broke my html)

Author Comment

ID: 40254558
Thanx Miguel I did the walk through as you indicated in an earlier message and I successfully got the mutli language to work using an ASPX file. But I am having trouble getting it to work on my ascx file.

I have 5 usercontrols and I need to get them all working with multi language. For example in Autos folder for example, I have the App_LocalResources folder that holds 3 resource files, one of which is Autos.aspx.en.resx. There is also the Autos.ascx user control file.

I had hard coded the controls to start but now I want localization. So do I have to replace the hard coded text with references like this throughout the user control:: Text="<%$ Resources:btnSearchAutos.Text %>"
LVL 36

Accepted Solution

Miguel Oz earned 2000 total points
ID: 40254641
The text property seems OK, but you are missing associated resx file for every user control.
Example: Autos.ascx will require Autos.ascx.resx
And then delete temporary ASP.NET files and rebuild your site for the changes to work.

If you are having user controls, you are better off using Explicit localization, but as you probably are finding out creating a file for every page and user control on your site is going to be time consuming.

Author Closing Comment

ID: 40261372
All your answers together helped figure it out thank you

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question