#1,114 – Culture Codes

In developing applications for Windows, a culture can be thought of as the combination of a particular language and the country or region where the language is being spoken.

Examples of specific cultures, representing a language and a region, include:

  • English / United States
  • English / United Kingdom
  • French / Belgium
  • French / France
  • German / Germany

Examples of neutral cultures, with no specific culture, include:

  • English
  • French
  • German

Cultures are represented in WPF by the use of culture codes or language tags, which conform to RFC 4646.  A language tag is composed of a code representing the language and a code representing the country or region, separated by a hyphen.

Below are several examples of names for specific cultures:

  • en-US  (English / United States)
  • en-GB  (English / United Kingdom)
  • fr-BE  (French / Belgium)
  • fr-FR  (French / France)
  • de-DE  (German / Germany)

A neutral culture is represented by the code for the language, by itself:

  • en  (English)
  • fr  (French)
  • de  (German)

#1,113 – Use of Cultures in Internationalization

When localizing an application or running a localized application, you’ll work in the context of a particular culture.  A culture can be thought of as the combination of a particular language and the country or region where the language is being spoken.

A developer targets one or more cultures when localizing an application.  For example, he might translate text in the application for the German-spoken-in-Austria culture or the English-spoken-in-the-UK culture.

Cultures are also used at run time.  A user runs an application within an environment that represents a particular culture.  This culture is then used by the application to determine which strings to load.

A culture that includes both a language and country/region indicator is known as a specific culture.  (E.g. French/Canada).  You can also work with neutral cultures, which are defined by a language but without a specific country.  (E.g. French)

#1,112 – Internationalization vs. Localization

Internationalization and localization both deal with adapting software to run as expected under a variety of different languages and/or geographic regions.

Internationalization, typically abbreviated as “i18n”, is the process of making changes to an application so that it could potentially later be adapted to one or more languages or regions.

Internationalization

  • Encompasses the things that you do just once, rather than once per target language/region
  • Must be done before localization
  • Includes activities like
    • Storing strings as Unicode
    • Being aware of regional settings when converting between numeric data and strings
    • Moving localizable resources into “satellite assemblies”
    • Removing hard-code constraints for certain UI elements

Localization, typically abbreviated as “l10n”, is the process of adapting an application for a specific language or region.

Localization

  • Is done once for each targeted language/region
  • Includes activities like
    • Translating strings for a particular language
    • Adjusting UI, as needed, to fit translated elements

#1,080 – Command Text for Preexisting Commands Is Automatically Localized

If you use any of the preexisting RoutedUICommand objects in your application, the Text property of the command is automatically localized to match the language of the operating system that you’re running on.

Assume that you wire a Button up to an Open command:

        <Button Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
                Command="ApplicationCommands.Open" />

If we run the application, the button text is in English.

1080-001

If we run the application on a French version of Windows, the text on the button will be localized.  Assuming that we have the proper language pack installed, we can also just override the CurrentUICulture of the current thread.

    public partial class App : Application
    {
        public App()
        {
           Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
        }
    }

Now when we run the application, the word “Open” is translated to French.
1080-002

#763 – The Difference Between CurrentCulture and CurrentUICulture

In a WPF application, you have access to two properties that give you information about the user’s culture and language.  They are both properties of a Thread object, which you can access via Thread.CurrentThread.

  • CurrentCulture – Tells you the user’s current locale, as set in the Region applet.  I.e.: Where is the user located?
  • CurrentUICulture – Tells you the native language of the version of Windows that is installed.  I.e.: What language does the user speak?

The user can change CurrentCulture using the Region applet.  It’s used to determine formatting for numeric and date/time strings.

763-001

The user normally can’t change CurrentUICulture without re-installing Windows.  It’s used to know what language to use when displaying text in your application.  (I.e. Which resource files to load).

            CultureInfo ci = Thread.CurrentThread.CurrentCulture;
            lblCurrentCulture.Content = string.Format("CurrentCulture = {0} - {1}", ci.Name, ci.DisplayName);

            ci = Thread.CurrentThread.CurrentUICulture;
            lblCurrentUICulture.Content = string.Format("CurrentUICulture = {0} - {1}", ci.Name, ci.DisplayName);

For example, someone in England might see:
763-002

#384 – The Benefits of Flow-Based Layout

WPF provides several benefits by making flow-based layout a default.

Resolution Independence

This is not really a benefit of flow-based layout, but a benefit based on the fact that WPF specifies positions and sizes in device independent units, rather than in pixels.  If the current DPI setting matches the native DPI of the device, then the actual size of the GUI elements will be as requested.

Controls Automatically Resized or Repositioned

Flow-based layout containers automatically reposition/resize child controls as the container is resized.

Controls Size to Fit Their Content

In WPF, you typically allow a control to size to fit it’s content.  This removes the need for tweaking size and position of elements if the content changes.

    <StackPanel>
        <Button Content="Bob" HorizontalAlignment="Center"/>
        <Button Content="John Jacob Jingleheimer Smith" HorizontalAlignment="Center"/>
    </StackPanel>

Easier Localization

When controls size to fit their content, you don’t need to tweak layout for each localized language.