On this page:
1.1 Locale Strings
locale-string?
make-locale-string
normalize-code-page
get-known-locales
1.2 Locale Accessors
set-minimal-locale
set-user-preferred-locale
get-locale
set-locale
get-collation-locale
set-collation-locale
get-character-type-locale
set-character-type-locale
get-monetary-locale
set-monetary-locale
get-numeric-locale
set-numeric-locale
get-time-locale
set-time-locale
get-messages-locale
set-messages-locale
1.3 Locale Conventions
grouping-repeats
grouping-ends
unspecified-sign-posn
locale
get-locale-conventions
8.12

1 Module locale🔗ℹ

 (require locale) package: racket-locale

This module has functions for managing locale strings, for getting and setting locales and retrieving locale-specific conventions. It is important to understand that there isn’t a single locale value that encompasses all purposes, there are a set of categories such as date/time handling, number and currency formatting, and string/character encoding, each of which may have a separate locale identified. In this module there are functions of the form get-category-locale and set-category-locale for each supported category.

Examples:
> (require locale)
> (set-user-preferred-locale)

"C"

> (get-locale)

"C"

> (set-numeric-locale "C")

"C"

> (get-locale)

"C"

> (set-locale
   (make-locale-string "en"
                       "GB"
                       #:code-page (normalize-code-page 'utf-8)))

#f

1.1 Locale Strings🔗ℹ

procedure

(locale-string? str)  boolean?

  str : string?
Returns #t if the provided string str is a correctly formatted locale name according to the following rules:

locale    := "C" | "POSIX" ; well-known portable locales

           | (language) ("_" territory)? ("." code-page)? ("@" modifier)

 

language  := [a-z]{2,3}    ; ISO 639 language code

 

territory := [A-Z]{2,3}    ; ISO 3166 country code

 

code-page := [a-zA-Z0-9\-]+

 

modifier  := [a-zA-Z0-9\-]+

The locale strings "C" and "POSIX" are defined for all systems and have well-known behavior.

procedure

(make-locale-string language    
  [country    
  #:code-page code-page    
  #:options modifier])  (or/c string? #f)
  language : string?
  country : string? = ""
  code-page : string? = ""
  modifier : string? = ""
Construct a locale string from the constituent components. Note that the same validation described for locale-string? will be applied, any invalid value will result in #f rather than a locale string.

procedure

(normalize-code-page code-page)  string?

  code-page : (or/c 'utf-8 'ascii 'iso-8859-1 'iso-8859-15)
Code page strings are also very system dependent, this helper takes in a symbol representing common page types and should return the system-dependent string version for use in make-locale-string.

This function will enumerate the set of locales known by the operating system on the current machine. Naming conventions for code pages and modifiers vary considerably by operating system. The result is a hash? where the top hash keys are the locale language, with the value being another hash. This second hash has the territory as the key and a list of code-page and modifier strings as the hash value.

Examples:
> (require locale)
> (get-known-locales)

'#hash()

1.2 Locale Accessors🔗ℹ

procedure

(set-minimal-locale)  (or/c locale-string? #f)

The locale "C" or "POSIX" is a portable locale; it exists on all conforming systems.

A system dependent way of setting a default locale, each part of the locale that should be modified is set according to the process environment.

procedure

(get-locale)  (or/c locale-string? #f)

This function will either 1) return a single string that is the common locale for all categories, or 2) return a ";" separated string list of category and locale pairs.

Examples:
> (require locale)
> (set-minimal-locale)

"C"

> (set-numeric-locale
   (make-locale-string "en"
                       "US"
                       #:code-page (normalize-code-page 'utf-8)))

#f

> (get-locale)

"C"

procedure

(set-locale locale)  (or/c locale-string? #f)

  locale : locale-string?
TBD

procedure

(get-collation-locale)  (or/c locale-string? #f)

Affects the behavior of strcoll and strxfrm.

procedure

(set-collation-locale locale)  (or/c locale-string? #f)

  locale : locale-string?
TBD

Affects character handling functions (all functions of <cctype>, except isdigit and isxdigit), and the multibyte and wide character functions.

procedure

(set-character-type-locale locale)  (or/c locale-string? #f)

  locale : locale-string?
TBD

procedure

(get-monetary-locale)  (or/c locale-string? #f)

Affects monetary formatting information returned by get-locale-conventions.

procedure

(set-monetary-locale locale)  (or/c locale-string? #f)

  locale : locale-string?

procedure

(get-numeric-locale)  (or/c locale-string? #f)

Affects the decimal-point character in formatted input/output operations and string formatting functions, as well as non-monetary information returned by get-locale-conventions.

procedure

(set-numeric-locale locale)  (or/c locale-string? #f)

  locale : locale-string?
TBD

procedure

(get-time-locale)  (or/c locale-string? #f)

Affects the behavior of strftime. locale

procedure

(set-time-locale locale)  (or/c locale-string? #f)

  locale : locale-string?
TBD

procedure

(get-messages-locale)  (or/c locale-string? #f)

Localizable natural-language messages.

procedure

(set-messages-locale locale)  (or/c locale-string? #f)

  locale : locale-string?
TBD

1.3 Locale Conventions🔗ℹ

An integer, used in the locale? grouping and monetary-grouping properties to denote that the group should repeat indefinitely.

An integer, used in the locale? grouping and monetary-grouping properties to denote that no further grouping should be performed.

An integer, used in the locale? pos-sign-posn, neg-sign-posn, international-pos-sign-posn, and international-neg-sign-posn properties.

struct

(struct locale (decimal-point
    thousands-separator
    grouping
    international-currency-symbol
    currency-symbol
    monetary-decimal-point
    monetary-thousands-separator
    monetary-grouping
    positive-sign
    negative-sign
    international-fractional-digits
    fractional-digits
    pos-cs-precedes
    neg-cs-precedes
    pos-sep-by-space
    neg-sep-by-space
    pos-sign-posn
    neg-sign-posn
    international-pos-cs-precedes
    international-neg-cs-precedes
    international-pos-sep-by-space
    international-neg-sep-by-space
    international-pos-sign-posn
    international-neg-sign-posn))
  decimal-point : string?
  thousands-separator : string?
  grouping : string?
  international-currency-symbol : string?
  currency-symbol : string?
  monetary-decimal-point : string?
  monetary-thousands-separator : string?
  monetary-grouping : vector?
  positive-sign : string?
  negative-sign : string?
  international-fractional-digits : integer?
  fractional-digits : integer?
  pos-cs-precedes : integer?
  neg-cs-precedes : integer?
  pos-sep-by-space : integer?
  neg-sep-by-space : integer?
  pos-sign-posn : integer?
  neg-sign-posn : integer?
  international-pos-cs-precedes : integer?
  international-neg-cs-precedes : integer?
  international-pos-sep-by-space : integer?
  international-neg-sep-by-space : integer?
  international-pos-sign-posn : integer?
  international-neg-sign-posn : integer?
This struct provides information on formatting numeric and monetary (not date) values. The properties are described in detail below.

For example, given the currency value 1.25 the table below shows the effect of the various formatting options above.

pos-sep-by-space =

0

1

2

pos-cs-precedes = 0

pos-sign-posn = 0

(1.25$)

(1.25 $)

(1.25 $)

pos-sign-posn = 1

+1.25$

+1.25 $

+1.25 $

pos-sign-posn = 2

 1.25$+

 1.25 $+

 1.25$ +

pos-sign-posn = 3

 1.25+$

 1.25 +$

 1.25+ $

pos-sign-posn = 4

 1.25$+

 1.25 $+

 1.25$ +

pos-cs-precedes = 1

pos-sign-posn = 0

($1.25)

($ 1.25)

($ 1.25)

pos-sign-posn = 1

+$1.25

+$ 1.25

+ $1.25

pos-sign-posn = 2

 $1.25+

 $ 1.25+

  $1.25 +

pos-sign-posn = 3

+$1.25

+$ 1.25

+ $1.25

pos-sign-posn = 4

$+1.25

$+ 1.25

$ +1.25

Return a locale? struct for the current locale settings.

Examples:
> (require locale)
> (set-locale
   (make-locale-string "en"
                       "GB"
                       #:code-page (normalize-code-page 'utf-8)))

#f

> (get-locale-conventions)

(locale

 "."

 ""

 '#(0)

 ""

 ""

 ""

 ""

 '#(0)

 ""

 ""

 127

 127

 127

 127

 127

 127

 127

 127

 127

 127

 127

 127

 127

 127)