Globalization/ Localization in website development

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

Globalization/ Localization in website development

Postposted on Thu Jun 03, 2010 12:53 pm

I've never had to make a site compatible with other languages and cultures, so it's been (and it is) an adventure for me. For what it's worth, I develop using the .Net framework primarily.

I've got the entire site programmed to accept resource files now (.resx) for dynamically changing the language and culture should someone desire it, and in my limited testing it works. I had a couple questions though:

1) In my design, I basically went through the entire site, and everywhere there was static text, I inserted an asp literal with the text pointing to the resource file. Is this the norm? Likewise for dynamic content, some controls and what not had to be tinkered with to display reports properly and in the right language.

2) For the proper translation, it was my understanding that I would just grab all the resource files that were culture/language neutral, slap a .fr,.es,.de etc on each one (so welcome.aspx.resx -> welcome.aspx.fr.resx for french) - This works, but my question is, how do I package these appropriately to have them translated? I'm using VS2008, I don't expect the translator to look at raw XML and translate it. Free software that can read and edit theses easily?

3) Any tips for developing in the future? This was a harder case scenario for me since the site was originally in classic asp, and I had to retrofit and reprogram many things to leverage the resources files and framework. This is my first crack at it.

FWIW I used a master page for each language that creates a Header with the language sensitive links for each possible choice. For switching the languages, I wrote a class called BasePage that all my pages except the master pages inherit. On page.init of BasePage, I set the Culture and UICulture to the appropriate language /region and I also declaratively set the masterpage to use. This seems to work well. I made a small dropdown list that my personal login only can use to change the language on the fly, and it seems to work as well. Like I said, first crack at it - anything I did stupid / made harder on myself?

thanks.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Sat Jun 05, 2010 12:24 am

Take a look at this: http://www.asp.net/general/videos/how-do-i-create-a-multi-lingual-site-with-localization
And then, of course, MSDN: http://msdn.microsoft.com/en-us/library/c6zyy3s9.aspx

Seems like you've done a lot of manual work that could be done a little bit easier with meta:resourceKey (I did not completely understand how exactly you did it, if this way - then yes, it is the norm). The video (the first link) shows how it could be implemented and what standard VS tools are used for this (mostly the default resource editor in VS - is it what you were looking for? Or I got it wrong?). MSDN documentation goes in depth on the topic.
i5 2500K@4.5GHz | Asus P8P67 PRO | 4x4GB DDR3 1600 | Radeon HD 7950 | Samsung 830 Pro 256GB| Antec Solo Black | CORSAIR 550VX | Dell 2407WFP-HC + Auria EQ276W
yuriylsh
Gerbil
 
Posts: 87
Joined: Tue May 26, 2009 3:52 pm
Location: KS, USA

Re: Globalization/ Localization in website development

Postposted on Wed Jun 09, 2010 8:02 am

When I generated the local resource file for any given document, it would use the meta:resourcekey. The problem was that it would often use silly naming conventions and create ugly formatted code in VS2008 (constantly splitting single server controls across 3+lines, pet peeve.... For example, I had a dropdownlist that I called DDLLanguageSelection. Instead of seeing 'DDLLanguageSelection' as the id in the resource file, I'd see something like DropDownList1. Completely useless. So all I really did was add the code '<%$resources:name%>' to the ID, THEN generate the file, and it would use the name I wanted. It would still generated duplicate resource keys for something I explicitly told it what to use, which also seems like a bug to me, but those were easily deleted from the resource file.

Thank you for the links, I'll be sure to watch the video and see what I did that I shouldn't have, and what I could have done better.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Mon Jun 14, 2010 2:02 pm

Another newbie question for localization: I have my French Canadian and US English site working properly (loading the en-US and fr resx files respectively) but I can't get my Canadian English files going, I assumed it would be en-CA but that doesn't work. What I am fearing is that I can't have a resx file for us english AND for canadian english, which differ in some cases I have.

edit: To be clear, I have 4 files right now for a welcome.aspx page. They are:

welcome.aspx.en-us.resx works
welcome.aspx.fr-ca.resx works
welcome.aspx.en-ca.resx doesn't work, claims resources file is missing something (or it can't find the resource file)
welcome.aspx.es-us.resx untested, in progress.

and last, the culture neutral welcome.aspx.resx file (in english) which works as well.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Mon Jun 14, 2010 3:29 pm

Not sure if it is going to help, but could you set the current culture in the InitializeCulture method instead of Page.Init an see if it works? Based on the list of your resource files you don't have troubles when it comes to language, but you do have one when it's the same language but different culture. Something like this:
Code: Select all
protected override void InitializeCulture()
{
    if (Request.Form["myDropDownWithLanguageSelection"] != null)
    {
        String selectedLanguage = Request.Form["myDropDownWithLanguageSelection"]; // this is gonna be en-CA in your case
        UICulture = selectedLanguage ;
        Culture = selectedLanguage ;

        Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture(selectedLanguage);
        Thread.CurrentThread.CurrentUICulture = new
            CultureInfo(selectedLanguage);
    }
    base.InitializeCulture();
}
i5 2500K@4.5GHz | Asus P8P67 PRO | 4x4GB DDR3 1600 | Radeon HD 7950 | Samsung 830 Pro 256GB| Antec Solo Black | CORSAIR 550VX | Dell 2407WFP-HC + Auria EQ276W
yuriylsh
Gerbil
 
Posts: 87
Joined: Tue May 26, 2009 3:52 pm
Location: KS, USA

Re: Globalization/ Localization in website development

Postposted on Mon Jun 14, 2010 7:31 pm

My code is very similar to yours, I have a class that inherits system.web.ui.page and inside there I have protected overrides sub initializeculture(). Therein I determine the language via a token that is decrypted on page init. The reason I did this on init is that, as I understand it, init only happens 1 time in the page life cycle so less of a hit for page refreshes and what not, and I have page-specific things that may or maynot run on page_load per page.

My code is at work atm (otherwise I'd just paste it) but it has no problem with me using en-ca as the uiculture and culture; however when the page loads the resource file for canadian english, it claims it can't find the first resource (the word "home") - yet it is in every single resx file I have including a culture neutral one. So my problem appears to be that I have set a culture and improperly named my file for locating the resource, or my file itself is somehow incorrect (the resource file that is).


Thanks again for your feedback. I'll paste my code first thing tomorrow.
\
edit: As fate would have it, I needed to patch something up at work, so I remoted in: Here's a snippet:

Code: Select all
Public Class BasePage
    Inherits System.Web.UI.Page
    Protected Overrides Sub InitializeCulture()
        MyBase.InitializeCulture()
        Select Case Session("language")
            Case "English"
                Me.MasterPageFile = "Master-EN.master"
                Me.Culture = "en-us"
                Me.UICulture = "en-us"
            Case "CanadianFrench"
                Me.MasterPageFile = "Master-FR.master"
                Me.Culture = "fr-ca"
                Me.UICulture = "fr-ca"
            Case "CanadianEnglish"
                Me.MasterPageFile = "Master-CE.master"
                Me.Culture = "en-ca"
                Me.UICulture = "en-ca"
            Case "Spanish"
                Me.MasterPageFile = "Master-ES.master"
                Me.Culture = "es-us"
                Me.UICulture = "es-us"
        End Select
    End Sub
End Class


Yes this could be written more elegantly, but for now I don't have control over how the information is passed to me, so I can't rely on the language selection to be properly formatted at this time to simply be passed into the culture and uiculture. :)
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Mon Jun 14, 2010 9:23 pm

Hmm, it's difficult to tell what's wrong in there without looking at the project, so I can only make trivial suggestions . I would try the basic stuff first, like setting a breakpoint somewhere later in the page life cycle (Page.Load for example) and see if the current culture is what you've set previously. You probably did this already. Then I would try to retrieve the value from the resource manually (using ResourceManager.GetString() at the Page.Load for example and see how it behaves)Then if everything looks fine but still does not work, I would just regenerate the en-CA resource file. You can use something like http://www.screwturn.eu/ResxSync.ashx to speed this up if your resources are big.
i5 2500K@4.5GHz | Asus P8P67 PRO | 4x4GB DDR3 1600 | Radeon HD 7950 | Samsung 830 Pro 256GB| Antec Solo Black | CORSAIR 550VX | Dell 2407WFP-HC + Auria EQ276W
yuriylsh
Gerbil
 
Posts: 87
Joined: Tue May 26, 2009 3:52 pm
Location: KS, USA

Re: Globalization/ Localization in website development

Postposted on Tue Jun 15, 2010 8:21 am

I am such an idiot; I was looking at the error and because the url of the address bar was welcome.aspx I incorrectly assumed the problem with lied therein. I forgot, and neglected to mention, that I have master pages in use that generate links and layout for each language differently. The problem was that I never generated the resource file for the Canadian English master page. :oops:

So now that's fixed. Thanks for the nifty tool, I've already written a nice little batch file for myself to sync all my files, should save lots of time. Thanks again!
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Tue Jun 15, 2010 9:27 am

You are welcome. I'm glad you fixed it :)
i5 2500K@4.5GHz | Asus P8P67 PRO | 4x4GB DDR3 1600 | Radeon HD 7950 | Samsung 830 Pro 256GB| Antec Solo Black | CORSAIR 550VX | Dell 2407WFP-HC + Auria EQ276W
yuriylsh
Gerbil
 
Posts: 87
Joined: Tue May 26, 2009 3:52 pm
Location: KS, USA

Re: Globalization/ Localization in website development

Postposted on Wed Jun 16, 2010 1:36 pm

I came across something rather disturbing to me. I have a page that upon page_load does some querying against a user's shopping cart. Now for display purposes only, I show them currency formatted in their culture. However, for querying the database, calculations etc, I use my own. The part that disturbs is that a calculation that drives one such query was failing as I tested in my fr-ca login, and upon inspecting it, it was passing a large formatted value (or so I thought) of 5,346. I checked and re-checked the math, and finally it dawned on me that 5,346 is actually 5.346 in my culture. It's formatted the code!

Are there norms for having my own code excluded within a page that contains a language change? I am bugged because I need to go back and check a bunch of other places that just happened to work, probably because the formatting didn't screw up anything but the data is probably wrong.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Fri Jun 18, 2010 8:41 am

OK better example; I'm currently logged in as CanadianEnglish customer. I have a SQLQuery that adds the current datetime to the order in the database. This query fails because as a Canadian English user, it formats the date funky - so it's using the globalization in my business logic, how do you work around this?

edit: I should have mentioned, I found a work around:\\
Code: Select all
Now().ToString("d", New Globalization.CultureInfo("en-us", False))


But this feels hacky. Ideally, it would only use the culture-specific formatting for display, and leave the data alone otherwise.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Sat Jun 19, 2010 3:59 pm

You might want to look at StackOverflow on this subject (or even post a new question.

Here's a related thread.
Image
Nitrodist
Grand Gerbil Poohbah
 
Posts: 3280
Joined: Wed Jul 19, 2006 1:51 am
Location: Minnesota

Re: Globalization/ Localization in website development

Postposted on Wed Aug 04, 2010 9:51 am

I'm nearly complete save for a little clean up work across languages and pages. One thing the client requested (which makes no sense to me) is that all Currency be displayed in USD. I'm almost positive that I am correct in stating that, for example, when a french user see "500,01 $" that s/he will understand that to be the same as "$500.01" and it's also understood this is USD.

Am I also correct that you can only set 1 culture per page such that it's not possible to have a particular control render in US-EN and everything else as the culture they've chosen?
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Globalization/ Localization in website development

Postposted on Sat Sep 11, 2010 10:20 am

steelcity_ballin wrote:I'm nearly complete save for a little clean up work across languages and pages. One thing the client requested (which makes no sense to me) is that all Currency be displayed in USD. I'm almost positive that I am correct in stating that, for example, when a french user see "500,01 $" that s/he will understand that to be the same as "$500.01" and it's also understood this is USD.

Am I also correct that you can only set 1 culture per page such that it's not possible to have a particular control render in US-EN and everything else as the culture they've chosen?

A lot of countries use the dollar sign. '$' ('S' with a single vertical strike) has been in use long before the US has been around. If there was a codepoint where the dollar symbol had two vertical strikes, you might have a case. (So far I've been unsuccessful at finding that codepoint.)

http://www.xe.com/symbols.php

Better to be specific.
The best things in life are free.
http://www.gentoo.org
Guy 1: Surely, you will fold with me.
Guy 2: Alright, but don't call me Shirley.
titan
Grand Gerbil Poohbah
 
Posts: 3276
Joined: Mon Feb 18, 2002 7:00 pm
Location: Great Smoky Mountains

Re: Globalization/ Localization in website development

Postposted on Sat Sep 11, 2010 11:48 am

steelcity_ballin wrote:I'm almost positive that I am correct in stating that, for example, when a french user see "500,01 $" that s/he will understand that to be the same as "$500.01" and it's also understood this is USD.

As a(n English) Canadian, I definitely prefer it when a site specifically says $500 USD or $500 CAD.

If I was on a .com site and noticed that they were using Canadian English, it would be easy to assume that Canadian site = Canadian prices.
Swampangel
Gerbil Team Leader
 
Posts: 287
Joined: Sun Aug 31, 2003 10:54 am
Location: Nova Scotia, Canada


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 2 guests