Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to develop a multilingual website?

    hi,
    I am trying to develop a multilingual website using .net c#
    in which i'll have three languages English,spanish,Arabic.
    Do anyone has code how to write the code in which onbuttonclick
    the respective culture will be launched and correspondind input
    language be activated programatically.

    Every kind of help will be appreciated.

    Thanks and Regards:
    Sant

  • #2
    New Coder
    Join Date
    Mar 2007
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup, I've recently done this hehe.

    #1 put this in the configuration section of your web.config
    Code:
    <globalization uiCulture="auto:en-US" culture="auto:en-US" />
    <anonymousIdentification enabled="true"/>
        <profile>
          <properties>
            <add name="Lang" type="string" 
                allowAnonymous="true" />
          </properties>
        </profile>
    Note: this will detect the browser/OS configuration and display the appropriate language, or fallback to english us, if you ant another default language, you gotta change en-US for the desired language and locale. Google is your friend :P

    Next, in your app_code folder, make a new class and call it BasePage, make it inherit from system.web.ui.page. In the code section, add this sub: (note, code is in C# and you might need to sue the imports on some pages too.)

    Code:
    using System.Resources;
    using System.Globalization;
    using System.Threading;
    
    ...
    
     protected override void InitializeCulture()
        {
            ProfileCommon Profile = (ProfileCommon)HttpContext.Current.Profile;
            string UserCulture = (String)Profile.GetPropertyValue("Lang");
            if (UserCulture != "")
            {
              // there is a user language setting in the profile: switch to it
              Thread.CurrentThread.CurrentUICulture = new CultureInfo(UserCulture);
              Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(UserCulture);
            }
        }
    now lets say you got that cool btnEnglish button on your page to switch the language to english, the btnEnglish_Click event should look like this
    Code:
    protected void btnEnglish_Click()
    {
      Profile.SetPropertyValue("Lang", "en-US");
      Profile.Save();
      Response.Redirect(Request.Url.PathAndQuery, false);
    }
    Next thing you need are the resource files.
    In your aspnet project, create the aspnet folder App_GlobalResources.
    Create a file you'll name global.resx (or whatever you want).
    Input a few keys in it, like Title "Hello World".
    Now copy the file in the same folder, and rename to global.es.resx, go and change the key values to the spanish text.

    To access it, all you need to do now is to use something like
    lblTitle.Text = (String)GetGlobalResourceObject("global", "Title");

    you can also use local files. the App_LocalResource folder has to be on the same level as the page, and you gotta name your files in it according to your page name (EG MyPage.aspx local resource files would be named MyPage.es.resx and MyPage.resx).

    You can add keys like MyLabel.Text "text of a label", MyLabel.ForeColor "Blue" and so on as if it was the label properties themself you were declaring, and then in your asp code you'd have
    Code:
    <asp:Label ID="lblTest" runat="server" meta:resourcekey="MyLabel" />
    You'll also need to make sure that all your pages inherit from your basepage instead of system.web.ui.page

    I hope that helped you. If you're still not too sure about it, search localization aspnet on google, there are plenty of tutorials out there, thats how I learned
    Last edited by Krokador; 04-25-2007 at 06:49 PM.

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot Krokador,
    But i have what u have given here ...and as i am new to this development environment i am unable to integrate all these things,
    so can u give me more specific codes for this.
    and one more problem is that i want my textboxes to take input in arabic from right to left....how to do that.

    Thanks.
    sant

  • #4
    New Coder
    Join Date
    Mar 2007
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well I could give you a small example zip, do you want VB.Net or C# ?
    And for the right to left hmm, I think that's do-able through resource files too, I just forgot the name of the property to set for that. I'll get back to you with that once I have a bit of time to put together the example.

  • #5
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Krokador View Post
    well I could give you a small example zip, do you want VB.Net or C# ?
    And for the right to left hmm, I think that's do-able through resource files too, I just forgot the name of the property to set for that. I'll get back to you with that once I have a bit of time to put together the example.
    Hi Krokador,
    i want codes in c#...thanks

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Location
    Skopje, Macedonia
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool

    You can just use database or xml files for all languages and using cookies or a table that will save the user's language and everytime the user goes to the site it wil be on its language. I woul suggest you to use database because it is easy to manage you have tables and everything is in one file and the xml will be more files - according to the languages that you want to use.


    So start to think of DATABASE!!!!!!


    Regards!

  • #7
    New Coder
    Join Date
    Mar 2007
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I havent had the time to build that example yet (will try during my lunch break today) but about what you said Lallo

    using the aspnet profiles IS storing into a database. Allowing anonymous just makes it so a user who cant login can also save his own preference (and as far as ive tested, it works, a computer will keep the info.)

    putting language files into the database makes for some fun doing the queries. You have to put in an if or a case statement depending on what language you want to load, whereas resource files (which are xml, btw) just need a call to the key name and voilà you get the right language thats stored in your profile whenever you visit the site.

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Location
    Skopje, Macedonia
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That was just an idea!!! I would do it this way!

    Regards!

  • #9
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Another idea:

    http://www.docstorus.com/viewer.aspx...9-ffd5fb72c8bc

    works pefectley for me


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •