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.17.0.6

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.

  • decimal-point - Decimal-point separator used for non-monetary quantities.

  • thousands-separator - Separators used to delimit groups of digits to the left of the decimal point for non-monetary quantities.

  • grouping - Specifies the amount of digits that form each of the groups to be separated by thousands-separator separator for non-monetary quantities. This is a vector? of nonnegative-integer? values that may contain different grouping sizes for each successive group starting from the right, each number indicating the amount of digits for the group. If the last number in the vector is grouping-repeats the previous value will be used for all remaining groups. For example, assuming thousands-separator is set to "," and the number to represent is one million (1000000):
    • with grouping set to '#(3 grouping-repeats), the number would be represented as: 1,000,000

    • with grouping set to '#(1 2 3 grouping-repeats), the number would be represented as: 1,000,00,0

    • with grouping set to '#(3 1 grouping-repeats), the number would be represented as: 1,0,0,0,000

    • grouping-ends indicates that no further grouping is to be performed.

  • international-currency-symbol - International currency symbol. This is formed by the three-letter ISO-4217 entry code for the currency, like "USD" for U.S.-Dollar or "GBP" for Pound Sterling, followed by the character used to separate this symbol from the monetary quantity.

  • currency-symbol - Local currency symbol, like "$".

  • monetary-decimal-point - Decimal-point separator used for monetary quantities.

  • monetary-thousands-separator - Separators used to delimit groups of digits to the left of the decimal point for monetary quantities.

  • monetary-grouping - Specifies the amount of digits that form each of the groups to be separated by monetary-thousands-separator separator for monetary quantities. See grouping description above.

  • positive-sign - Sign to be used for nonnegative (positive or zero) monetary quantities.

  • negative-sign - Sign to be used for negative monetary quantities.

  • international-fractional-digits - Same as fractional-digits, but for the international format (instead of the local format).

  • fractional-digits - Amount of fractional digits to the right of the decimal point for monetary quantities in the local format.

  • pos-cs-precedes - Whether the currency symbol should precede nonnegative (positive or zero) monetary quantities. If this value is 1, the currency symbol should precede; if it is 0, it should follow.

  • neg-cs-precedes - Whether the currency symbol should precede negative monetary quantities. If this value is 1, the currency symbol should precede; if it is 0 it should follow.

  • pos-sep-by-space - Whether a space should appear between the currency symbol and nonnegative (positive or zero) monetary quantities. If this value is 1, a space should appear; if it is 0 it should not.

  • neg-sep-by-space - Whether a space should appear between the currency symbol and negative monetary quantities. If this value is 1, a space should appear; if it is 0 it should not.

  • pos-sign-posn - Position of the sign for nonnegative (positive or zero) monetary quantities:
    • 0 : Currency symbol and quantity surrounded by parentheses.

    • 1 : Sign before the quantity and currency symbol.

    • 2 : Sign after the quantity and currency symbol.

    • 3 : Sign right before currency symbol.

    • 4 : Sign right after currency symbol.

    • unspecified-sign-posn : unspecified.

  • neg-sign-posn - Position of the sign for negative monetary quantities. See pos-sign-posn above.

  • international-pos-cs-precedes - Same as pos-cs-precedes, but for the international format.

  • international-neg-cs-precedes - Same as neg-cs-precedes, but for the international format.

  • international-pos-sep-by-space - Same as pos-sep-by-space, but for the international format.

  • international-neg-sep-by-space - Same as neg-sep-by-space, but for the international format.

  • international-pos-sign-posn - Same as pos-sign-posn, but for the international format.

  • international-neg-sign-posn - Same as neg-sign-posn, but for the international format.

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)