Multilanguage Website

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sfreak
    New Member
    • Mar 2010
    • 64

    #1

    Multilanguage Website

    Hi folks,

    I am trying to change the language of my website dinamically. So, i have created a global resource file(.resx) for each language I want to display. For example: LanguageEnUs.re sx, LanguagePtBr.re sx, etc...

    The user would be able to switch the language whenever he wants, so I must load the .resx on his request.

    I have already done it programatically using
    Code:
    globalresourcestring = (String)GetGlobalResourceObject("LanguageEnUs", "Greetings")
    It works fine... but I would like to use it on my HTML tags using the expression

    Code:
    <%$ Resources:Class, ResourceID %>
    as the following example:

    Code:
    <asp:Label ID="lblErrorMsg" runat="server" Text="<%$ Resources:LanguageEnUs, lblErrorsgText %>"></asp:Label>
    My question is:

    How do I change the static LanguageEnUs in this expression for a variable that I can recover from somewhere else? Or better... is this possible?

    Thanks in advance,

    Fernando Mello
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You are currently doing more work than you need to.
    If you name your resources properly, and you configure things right, you don't have to do any of this. The browser will pick up the end users' culture settings and relay that to the server. The server will automatically load the resource (that is named properly) that fits with that culture.

    If you want to specifically set the language, you simply need to change the culture of the Thread.

    Since the resources are loaded according to the users cultural settings before the Page Load event, if you set the culture you will need to re-request the page to load it with the correct language settings.

    You'll have to save the culture settings that aren't the default settings somewhere (viewstate or session or something).

    There are a lot of articles in the MSDN Library that cover the topic. Like this one: ASP.NET Globalization and Localization and this one: Walkthrough: Using Resources for Localization with ASP.NET.

    -Frinny

    Comment

    Working...