Click here to Skip to main content
14,297,239 members

Gender Aware Localization in ASP.NET

Rate this:
5.00 (1 vote)
Please Sign up or sign in to vote.
5.00 (1 vote)
21 Apr 2009CPOL
Implementing localization which depends on the gender of the registered user (ASP.NET).


A while ago, I needed to implement localization depending also on the gender of the registered user, something obviously more relevant to languages other than English (for example, mine - Hebrew). After playing around a bit with writing my own custom ResourceManager/Provider classes, I decided to follow a suggestion I received for a much simpler way - create my own custom cultures for each required language.

Step 1 - Create your own custom culture

For each language required, create a custom "female" culture as a clone of the original culture. For example, the following code creates a custom culture named 'he-IL-f' which is a clone of 'he-IL'. Install the culture on your machine. You can verify the installation was successful by viewing your “C:\Windows\Globalization” folder after running the exe.

CultureAndRegionInfoBuilder cib = 
  new CultureAndRegionInfoBuilder("he-IL-f", CultureAndRegionModifiers.None);
// Populate the new CultureAndRegionInfoBuilder object with culture information.
CultureInfo ci = new CultureInfo("he-IL");

// Populate the new CultureAndRegionInfoBuilder object with region information.
RegionInfo ri = new RegionInfo("IL");

cib.Parent = ci;


* The above code needs admin rights to execute, so if in Vista, run the exe “as admin”.

The fallback culture of the new culture will be the original one – this is why we have this line:

cib.Parent = ci;

This enables us to only enter the strings that need changing in the "female" RESX files.

Step 2 - Create the correspondingly names RESX files

Notice that in the “female” RESX files, you only need to insert those strings which differ from their “male” version.

Step 3 - Set the thread's UICulture property

protected override void InitializeCulture()
    string culture = "";

    if (Request.Form["DropDownListCulture"] != null)
                 string gender = Request.Form["DropDownListGender"];
        bool isFemale = (gender == "Female");

        culture = Request.Form["DropDownListCulture"];
        dir = (culture == "he-IL") ? "rtl" : "ltr";

        if (isFemale)
            culture += "-f";

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

In my example I used the InitializeCulture event of the page to perform the logic. In more complex systems, we’d probably want to move this logic to a more centralized location (perhaps some event in the Application level). I receive two parameters from the form – language and gender. Of course, in a real application, we would have this information per user and use it automatically upon login.

Using the code / Points of interest

  1. In the source code supplied, we register three custom cultures: en-US-f, he-IL-f, and fr-FR-f.
  2. You can verify this by checking your “C:\Windows\Globalization” folder after running the exe.

  3. Note that the French culture was registered without this line of code: cib.Parent = ci;.
  4. This means that instead of falling back to fr-FR, it falls back to the default culture (en-US, in our case).

    This is demonstrated when using the global resource ‘Talya’ (at the bottom of the page): its default in English is ‘talya’, and it is overridden in the he-IL and fr-FR cultures, but not in their female versions.

    When viewed with the he-IL-f culture, it falls back to the Hebrew resource ‘טליה’. However, when viewed with the fr-FR-f culture instead of falling back to ‘talya (French)’, it falls back to the English ‘talya’. This is because we didn’t set the French female culture’s parent to the French culture.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Talya Gendler
Software Developer
Israel Israel
No Biography provided

Comments and Discussions

GeneralJust curious Pin
Johnny J.21-Apr-09 21:00
professionalJohnny J.21-Apr-09 21:00 
JokeRe: Just curious Pin
leonardas22-Apr-09 0:27
memberleonardas22-Apr-09 0:27 
GeneralRe: Just curious Pin
Johnny J.22-Apr-09 0:44
professionalJohnny J.22-Apr-09 0:44 
AnswerRe: Just curious Pin
Talya Gendler22-Apr-09 10:43
memberTalya Gendler22-Apr-09 10:43 
GeneralRe: Just curious Pin
Johnny J.22-Apr-09 20:29
professionalJohnny J.22-Apr-09 20:29 
GeneralRe: Just curious Pin
ProJee29-Apr-09 3:48
memberProJee29-Apr-09 3:48 
GeneralRe: Just curious Pin
Talya Gendler29-Apr-09 22:45
memberTalya Gendler29-Apr-09 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 21 Apr 2009


10 bookmarked