Localizing Date and Time Labels (Part 1)

by Feb 15, 2022

Windows comes with built-in support for various cultures. Here is the list of supported cultures and their short name:

 
PS> [System.Globalization.CultureInfo]::GetCultures('AllCultures') | Select-Object -Property Name, DisplayName

Name           DisplayName                                     
----           -----------                                     
aa             Afar                                            
aa-DJ          Afar (Djibouti)                                 
aa-ER          Afar (Eritrea)                                  
aa-ET          Afar (Ethiopia)                                 
af             Afrikaans                                       
af-NA          Afrikaans (Namibia)                             
af-ZA          Afrikaans (South Africa)  
...
 

It also comes with fully translated expressions for date and time components. If you’d like to know the weekday names used in Kikuyu (Kenya), look up the appropriate culture name (“ki”), then try this:

 
PS> [System.Globalization.CultureInfo]::GetCultureInfo( 'ki' ).DateTimeFormat.DayNames
Kiumia
Njumatatu
Njumaine
Njumatana
Aramithi
Njumaa
Njumamothi
 

You could even create a “translation table” for multiple languages because what you see in DayNames is an array with a numeric index:

 
PS> [System.Globalization.CultureInfo]::GetCultureInfo( 'ki' ).DateTimeFormat.DayNames[0]
Kiumia
 

Here is a translation table showing English and Chinese day names:

$english = [System.Globalization.CultureInfo]::GetCultureInfo( 'en' ).DateTimeFormat.DayNames
$chinese = [System.Globalization.CultureInfo]::GetCultureInfo( 'zh' ).DateTimeFormat.DayNames

for($x=0 $x-lt7; $x++)
{

    [PSCustomObject]@{
        English = $english[$x]
        Chinese = $chinese[$x]
    }     
}

The result looks like this:

 
English   Chinese
-------   -------
Sunday    星期日    
Monday    星期一    
Tuesday   星期二    
Wednesday 星期三    
Thursday  星期四    
Friday    星期五    
Saturday  星期六    
 


Twitter This Tip! ReTweet this Tip!