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"

2 comments:

Mombo said...

You have a cut & paste error at line 17. You left the word Chinese when you wanted Spanish.

Thomas Lee said...

Nice catch - fixed.

Thanks!