
collsort:

  # collated sort helper script

  # see also demo.tcl

  package require collsort
  package require locale

  locale all set {} ; # set the locale from the environment variables

  set mylist [list \u00c4 B Z A \u00e9 e f]
  set nl [::collsort::lsort $mylist]
  puts $nl

locale:

  # locale package, a wrapper around setlocale().
  # has some handlers to deal with LC_NUMERIC and LC_MESSAGES.

  package require locale

  locale <type> get
  locale <type> set <locale>

  Where type is one of:
    all, collate, messages, monetary, numeric, time

  # Initialize all LC_* settings from the environment.
  # Note that the LC_NUMERIC locale is saved internally, and reset to 'C'.

  locale all set {}

  # [locale values] returns some information if you want to use
  # it directly in your program.
  # Note that: 'locale all set {}' must be called,

  locale values
  -> decimal_point , thousands_sep . grouping 33 currency_symbol €

  # Getting LC_NUMERIC will return the correct value, though
  # in reality, it is still set to 'C'.

  locale numeric get
  -> de_DE.UTF-8

  # The format statement is locale aware.
  # Setting LC_NUMERIC explicitly works, but you have to remember to
  # change it back.

  locale numeric set de_DE.UTF-8
  set x [format %.1f 1.5]
  -> 1,5
  locale numeric set C

  # scan is not locale aware
  # this regsub handles 90+% of the different locales, I expect

  regsub , $x . x
  scan $x %f myvalue

  # Windows: LC_MESSAGES returns the LC_ALL setting

  locale messages get
  -> de_DE.UTF-8

  # Windows: setting LC_MESSAGES saves the value, but doesn't change any
  # locale settings.

  locale messages set en_US.UTF-8
  locale messages get
  -> en_US.UTF-8

collate:

  package require collate

  ::lsort -command collate $mylist
