Share via


CultureInfo.TwoLetterISOLanguageName Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the ISO 639-1 two-letter code for the language of the current CultureInfo.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overridable ReadOnly Property TwoLetterISOLanguageName As String
public virtual string TwoLetterISOLanguageName { get; }

Property Value

Type: System.String
The ISO 639-1 two-letter code for the language of the current CultureInfo object.

Remarks

For example, the two-letter abbreviation for English is "en". For the invariant culture, the TwoLetterISOLanguageName property returns the string "iv".

Examples

The following example displays the value of the TwoLetterISOLanguageName property for selected cultures. It then uses this value to instantiate a CultureInfo object, which it compares with the parent culture returned by the selected culture's Parent property. As the output shows, in most cases these two CultureInfo objects are equal. (The exact output may vary, depending on the platform on which the example is run.)

Imports System.Globalization

Module Example
   ' Define an array of selected culture names.
   Dim cultureCodes() As String = {"ar-JO", "ar-SY", "az-Cyrl-AZ", "az-Latn-AZ", "zh-CN", _
                                   "zh-SG", "zh-TW", "nl-BE", "nl-NL", "en-BZ", "en-CA", _
                                   "en-NZ", "en-GB", "en-US", "fr-BE", "fr-CA", "fr-FR", _
                                   "de-AT", "de-DE", "de-CH", "it-IT", "it-CH", "ms-BN", _
                                   "ms-MY", "nb-NO", "nn-NO", "pt-BR", "pt-PT", "sr-Cyrl-CS", _
                                   "sr-Latn-CS", "es-AR", "es-DO", "es-MX", "es-ES", _
                                   "es-ES_tradnl", "sv-FI", "sv-SE", "uz-Cyrl-UZ", "uz-Latn-UZ"}

   Public Sub Demo(outputBlock As System.Windows.Controls.TextBlock)
      Dim exCultureName As String = String.Empty

      ' Iterate array and create a CultureInfo object for each culture name.
      For Each cultureCode As String In cultureCodes
          Try
            exCultureName = cultureCode
            outputBlock.Text += String.Format("{0}: ", cultureCode)
            Dim ci As New CultureInfo(cultureCode)
            ' Get this culture's parent.
            Dim cip As CultureInfo = ci.Parent
            outputBlock.Text += String.Format("Parent is {0}, ", cip.Name)
            ' Get the culture's two-letter language name.
            Dim isoName As String = ci.TwoLetterISOLanguageName
            outputBlock.Text += String.Format("Language name is '{0}', ", isoName)
            ' Instantiate the neutral culture using the two-letter language name.
            exCultureName = isoName
            Dim ciNeutral As New CultureInfo(isoName)

            ' Determine whether the parent object equals the neutral culture.
            outputBlock.Text += String.Format("Equality: {0}", _
                                              cip.Equals(ciNeutral)) + vbCrLf
         Catch e As ArgumentException
            outputBlock.Text += String.Format("Unable to instantiate culture '{0}'.", exCultureName) + vbCrLf
         End Try
      Next
   End Sub
End Module
' The example displays the following output:
'    ar-JO: Parent is ar, Language name is 'ar', Equality: True
'    ar-SY: Parent is ar, Language name is 'ar', Equality: True
'    az-Cyrl-AZ: Parent is az, Language name is 'az', Equality: True
'    az-Latn-AZ: Parent is az, Language name is 'az', Equality: True
'    zh-CN: Parent is zh-Hans, Language name is 'zh', Unable to instantiate culture 'zh'.
'    zh-SG: Parent is zh-Hans, Language name is 'zh', Unable to instantiate culture 'zh'.
'    zh-TW: Parent is zh-Hant, Language name is 'zh', Unable to instantiate culture 'zh'.
'    nl-BE: Parent is nl, Language name is 'nl', Equality: True
'    nl-NL: Parent is nl, Language name is 'nl', Equality: True
'    en-BZ: Parent is en, Language name is 'en', Equality: True
'    en-CA: Parent is en, Language name is 'en', Equality: True
'    en-NZ: Parent is en, Language name is 'en', Equality: True
'    en-GB: Parent is en, Language name is 'en', Equality: True
'    en-US: Parent is en, Language name is 'en', Equality: True
'    fr-BE: Parent is fr, Language name is 'fr', Equality: True
'    fr-CA: Parent is fr, Language name is 'fr', Equality: True
'    fr-FR: Parent is fr, Language name is 'fr', Equality: True
'    de-AT: Parent is de, Language name is 'de', Equality: True
'    de-DE: Parent is de, Language name is 'de', Equality: True
'    de-CH: Parent is de, Language name is 'de', Equality: True
'    it-IT: Parent is it, Language name is 'it', Equality: True
'    it-CH: Parent is it, Language name is 'it', Equality: True
'    ms-BN: Parent is ms, Language name is 'ms', Equality: True
'    ms-MY: Parent is ms, Language name is 'ms', Equality: True
'    nb-NO: Parent is no, Language name is 'nb', Unable to instantiate culture 'nb'.
'    nn-NO: Parent is no, Language name is 'nn', Unable to instantiate culture 'nn'.
'    pt-BR: Parent is pt, Language name is 'pt', Equality: True
'    pt-PT: Parent is pt, Language name is 'pt', Equality: True
'    sr-Cyrl-CS: Parent is , Language name is 'sr', Unable to instantiate culture 'sr'.
'    sr-Latn-CS: Parent is , Language name is 'sr', Unable to instantiate culture 'sr'.
'    es-AR: Parent is es, Language name is 'es', Equality: True
'    es-DO: Parent is es, Language name is 'es', Equality: True
'    es-MX: Parent is es, Language name is 'es', Equality: True
'    es-ES: Parent is es, Language name is 'es', Equality: True
'    es-ES_tradnl: Parent is es, Language name is 'es', Equality: True
'    sv-FI: Parent is sv, Language name is 'sv', Equality: True
'    sv-SE: Parent is sv, Language name is 'sv', Equality: True
'    uz-Cyrl-UZ: Parent is uz, Language name is 'uz', Equality: True
'    uz-Latn-UZ: Parent is uz, Language name is 'uz', Equality: True
using System;
using System.Globalization;
using System.Threading;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Define an array of selected culture names.
      string[] cultureCodes = {"ar-JO", "ar-SY", "az-Cyrl-AZ", "az-Latn-AZ", "zh-CN", 
                               "zh-SG", "zh-TW", "nl-BE", "nl-NL", "en-BZ", "en-CA", 
                               "en-NZ", "en-GB", "en-US", "fr-BE", "fr-CA", "fr-FR", 
                               "de-AT", "de-DE", "de-CH", "it-IT", "it-CH", "ms-BN",
                               "ms-MY", "nb-NO", "nn-NO", "pt-BR", "pt-PT", "sr-Cyrl-CS", 
                               "sr-Latn-CS", "es-AR", "es-DO", "es-MX", "es-ES", 
                               "es-ES_tradnl", "sv-FI", "sv-SE", "uz-Cyrl-UZ", "uz-Latn-UZ"};
      string exCultureName = null;

      // Iterate array and create a CultureInfo object for each culture name.
      foreach (string cultureCode in cultureCodes)
      {
         try {
            exCultureName = cultureCode;
            outputBlock.Text += String.Format("{0}: ", cultureCode);
            CultureInfo ci = new CultureInfo(cultureCode);
            // Get this culture's parent.
            CultureInfo cip = ci.Parent;
            outputBlock.Text += String.Format("Parent is {0}, ", cip.Name);
            // Get the culture's two-letter language name.
            string isoName = ci.TwoLetterISOLanguageName;
            outputBlock.Text += String.Format("Language name is '{0}', ", isoName);
            // Instantiate the neutral culture using the two-letter language name.
            exCultureName = isoName;
            CultureInfo ciNeutral = new CultureInfo(isoName);

            // Determine whether the parent object equals the neutral culture.
            outputBlock.Text += String.Format("Equality: {0}\n", 
                                              cip.Equals(ciNeutral));
         }
         catch (ArgumentException) {
            outputBlock.Text += String.Format("Unable to instantiate culture '{0}'.\n", exCultureName);
         }
      }
   }
}
// The example displays the following output:
//    ar-JO: Parent is ar, Language name is 'ar', Equality: True
//    ar-SY: Parent is ar, Language name is 'ar', Equality: True
//    az-Cyrl-AZ: Parent is az, Language name is 'az', Equality: True
//    az-Latn-AZ: Parent is az, Language name is 'az', Equality: True
//    zh-CN: Parent is zh-Hans, Language name is 'zh', Unable to instantiate culture 'zh'.
//    zh-SG: Parent is zh-Hans, Language name is 'zh', Unable to instantiate culture 'zh'.
//    zh-TW: Parent is zh-Hant, Language name is 'zh', Unable to instantiate culture 'zh'.
//    nl-BE: Parent is nl, Language name is 'nl', Equality: True
//    nl-NL: Parent is nl, Language name is 'nl', Equality: True
//    en-BZ: Parent is en, Language name is 'en', Equality: True
//    en-CA: Parent is en, Language name is 'en', Equality: True
//    en-NZ: Parent is en, Language name is 'en', Equality: True
//    en-GB: Parent is en, Language name is 'en', Equality: True
//    en-US: Parent is en, Language name is 'en', Equality: True
//    fr-BE: Parent is fr, Language name is 'fr', Equality: True
//    fr-CA: Parent is fr, Language name is 'fr', Equality: True
//    fr-FR: Parent is fr, Language name is 'fr', Equality: True
//    de-AT: Parent is de, Language name is 'de', Equality: True
//    de-DE: Parent is de, Language name is 'de', Equality: True
//    de-CH: Parent is de, Language name is 'de', Equality: True
//    it-IT: Parent is it, Language name is 'it', Equality: True
//    it-CH: Parent is it, Language name is 'it', Equality: True
//    ms-BN: Parent is ms, Language name is 'ms', Equality: True
//    ms-MY: Parent is ms, Language name is 'ms', Equality: True
//    nb-NO: Parent is no, Language name is 'nb', Unable to instantiate culture 'nb'.
//    nn-NO: Parent is no, Language name is 'nn', Unable to instantiate culture 'nn'.
//    pt-BR: Parent is pt, Language name is 'pt', Equality: True
//    pt-PT: Parent is pt, Language name is 'pt', Equality: True
//    sr-Cyrl-CS: Parent is , Language name is 'sr', Unable to instantiate culture 'sr'.
//    sr-Latn-CS: Parent is , Language name is 'sr', Unable to instantiate culture 'sr'.
//    es-AR: Parent is es, Language name is 'es', Equality: True
//    es-DO: Parent is es, Language name is 'es', Equality: True
//    es-MX: Parent is es, Language name is 'es', Equality: True
//    es-ES: Parent is es, Language name is 'es', Equality: True
//    es-ES_tradnl: Parent is es, Language name is 'es', Equality: True
//    sv-FI: Parent is sv, Language name is 'sv', Equality: True
//    sv-SE: Parent is sv, Language name is 'sv', Equality: True
//    uz-Cyrl-UZ: Parent is uz, Language name is 'uz', Equality: True
//    uz-Latn-UZ: Parent is uz, Language name is 'uz', Equality: True

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.