Sunday, 22 January 2012

New-SpanishCulture.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script creates a Spanish cultureinfo object with a traditional 
  4.      sort and another with an international sort. The script then compares them. 
  5. .DESCRIPTION 
  6.     This script re-implements an MSDN sample.  
  7. .NOTES 
  8.     File Name  : New-SpanishCulture.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN sample posted to: 
  15.          http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx    
  16. .EXAMPLE 
  17.     C:\foo> .\New-SpanishCulture.ps1 
  18.         PROPERTY                       INTERNATIONAL                                  TRADITIONAL               
  19.     CompareInfo                    CompareInfo - es-ES                            CompareInfo - es-ES_tradnl 
  20.     DisplayName                    Spanish (Spain)                                Spanish (Spain)           
  21.     EnglishName                    Spanish (Spain, International Sort)            Spanish (Spain, Traditional Sort) 
  22.     IsNeutralCulture               False                                          False                     
  23.     IsReadOnly                                                                    False                     
  24.     LCID                           3082                                           1034                      
  25.     Name                           es-ES                                          es-ES                     
  26.     NativeName                     Español (España, alfabetización internacional) Español (España, alfabetización tradicional) 
  27.     Parent                         es                                             es                        
  28.     TextInfo                       TextInfo - es-ES                               TextInfo - es-ES_tradnl   
  29.     ThreeLetterISOLanguageName     spa                                            spa                       
  30.     ThreeLetterWindowsLanguageName ESN                                            ESP                       
  31.     TwoLetterISOLanguageName       es                                             es                        
  32.  
  33.     Comparing [llegar] and [lugar] 
  34.        With myCIintl.CompareInfo.Compare: -1 
  35.        With myCItrad.CompareInfo.Compare: 1 
  36. #> 
  37.  
  38. # Create and initialize the CultureInfo which uses the international sort 
  39. $myCIintl = New-Object System.Globalization.CultureInfo "es-ES", $false 
  40.  
  41. # Create and initialize the CultureInfo which uses the traditional sort 
  42. $myCItrad = New-Object System.Globalization.CultureINfo 0x040A, $false 
  43.  
  44. # Display the properties of each culture. 
  45. "{0,-31}{1,-47}{2,-25}" -f "PROPERTY", "INTERNATIONAL", "TRADITIONAL" 
  46. "{0,-31}{1,-47}{2,-25}" -f "CompareInfo", $myCIintl.CompareInfo, $myCItrad.CompareInfo 
  47. "{0,-31}{1,-47}{2,-25}" -f "DisplayName", $myCIintl.DisplayName, $myCItrad.DisplayName 
  48. "{0,-31}{1,-47}{2,-25}" -f "EnglishName", $myCIintl.EnglishName, $myCItrad.EnglishName 
  49. "{0,-31}{1,-47}{2,-25}" -f "IsNeutralCulture", $myCIintl.IsNeutralCulture, $myCItrad.IsNeutralCulture 
  50. "{0,-31}{1,-47}{2,-25}" -f "IsReadOnly", $myCIintl.$IsReadOnly, $myCItrad.IsReadOnly 
  51. "{0,-31}{1,-47}{2,-25}" -f "LCID", $myCIintl.LCID, $myCItrad.LCID 
  52. "{0,-31}{1,-47}{2,-25}" -f "Name", $myCIintl.Name, $myCItrad.Name 
  53. "{0,-31}{1,-47}{2,-25}" -f "NativeName", $myCIintl.NativeName, $myCItrad.NativeName 
  54. "{0,-31}{1,-47}{2,-25}" -f "Parent", $myCIintl.Parent, $myCItrad.Parent 
  55. "{0,-31}{1,-47}{2,-25}" -f "TextInfo", $myCIintl.TextInfo, $myCItrad.TextInfo 
  56. "{0,-31}{1,-47}{2,-25}" -f "ThreeLetterISOLanguageName", $myCIintl.ThreeLetterISOLanguageName, $myCItrad.ThreeLetterISOLanguageName 
  57. "{0,-31}{1,-47}{2,-25}" -f "ThreeLetterWindowsLanguageName",$myCIintl.ThreeLetterWindowsLanguageName, $myCItrad.ThreeLetterWindowsLanguageName 
  58. "{0,-31}{1,-47}{2,-25}" -f "TwoLetterISOLanguageName", $myCIintl.TwoLetterISOLanguageName, $myCItrad.TwoLetterISOLanguageName 
  59. "" 
  60.  
  61. # Compare two strings using myCIintl 
  62. "Comparing [llegar] and [lugar]" 
  63. "   With myCIintl.CompareInfo.Compare: {0}" -f $myCIintl.CompareInfo.Compare("llegar", "lugar"
  64. "   With myCItrad.CompareInfo.Compare: {0}" -f $myCItrad.CompareInfo.Compare("llegar", "lugar"

Show-ChineeseParentCulture.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the parent culture of each  
  4.     specific culture using the Chinese language. 
  5. .DESCRIPTION 
  6.     This script looks at each Chineese culture and displays 
  7.     the culture name and the parent.  
  8. .NOTES 
  9.     File Name  : Show-ChineeseParentCulture.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15.     MSDN sample posted to: 
  16.          http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx    
  17. .EXAMPLE 
  18.     C:\foo> .\Show-ChineeseParentCulture.ps1 
  19.     SPECIFIC CULTURE                                     PARENT CULTURE 
  20.     0x0804 zh-CN Chinese (Simplified, PRC)               0x0004 zh-CHS Chinese (Simplified) Legacy 
  21.     0x0C04 zh-HK Chinese (Traditional, Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) Legacy 
  22.     0x1404 zh-MO Chinese (Traditional, Macao S.A.R.)     0x7C04 zh-CHT Chinese (Traditional) Legacy 
  23.     0x1004 zh-SG Chinese (Simplified, Singapore)         0x0004 zh-CHS Chinese (Simplified) Legacy 
  24.     0x0404 zh-TW Chinese (Traditional, Taiwan)           0x7C04 zh-CHT Chinese (Traditional) Legacy     
  25. #> 
  26.  
  27. # Display a header 
  28. "SPECIFIC CULTURE                                     PARENT CULTURE" 
  29.  
  30. # Determine the specific cultures that use the Chinese language, and displays the parent culture 
  31.  
  32. ForEach ($ci in [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::SpecificCultures))  { 
  33.   if ($ci.TwoLetterISOLanguageName -eq "zh"
  34.    { 
  35.     $s1 = "0x{0} {1} {2,-40}" -f $ci.LCID.ToString("X4"), $ci.Name, $ci.EnglishName 
  36.     $s2 = "0x{0} {1} {2}" -f $ci.Parent.LCID.ToString("X4"), $ci.Parent.Name, $ci.Parent.EnglishName 
  37.     "{0}{1}" -f $s1, $s2 
  38.   }