In the previous tip we explained how you can see all supported Windows cultures and have Windows translate weekday names. Let’s have some more fun with this, and translate month names.
Here is a particularly simple way of identifying the short name for a culture that you’d like to use:
[System.Globalization.CultureInfo]::GetCultures('AllCultures') | Where-Object Name | Select-Object -Property Name, DisplayName | Out-GridView -Title 'Select Culture' -OutputMode Single
This opens a grid view window with all supported cultures. Use the empty text box located in its top to filter cultures, then select one and click OK in the bottom right corner. What you need is the short name of the culture to use. For example, to use Russian culture, the short name is “ru”.
Now, replace the selected culture name in the following call:
PS> [System.Globalization.CultureInfo]::GetCultureInfo( 'ru' ).DateTimeFormat.MonthNames Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь
Likewise, you can adjust the code from our previous tip to create a translation table for two languages:
$english = [System.Globalization.CultureInfo]::GetCultureInfo( 'en' ).DateTimeFormat.MonthNames $russian = [System.Globalization.CultureInfo]::GetCultureInfo( 'ru' ).DateTimeFormat.MonthNames for($x=0 $x-lt 12 $x++) { [PSCustomObject]@{ Id = $x+1 English = $english[$x] Russian = $russian[$x] } }
The result looks similar to this:
Id English Russian -- ------- ------- 1 January Январь 2 February Февраль 3 March Март 4 April Апрель 5 May Май 6 June Июнь 7 July Июль 8 August Август 9 September Сентябрь 10 October Октябрь 11 November Ноябрь 12 December Декабрь