CLDR Core
1 Locale Support
all-locales
modern-locales
locale?
modern-locale?
available-locales
2 Accessing CLDR JSON Data
cldr-ref
cldr-ref*
cldr-json
raise-locale-not-found
exn:  cldr
exn:  cldr:  locale-not-found
cldr-key/  c
cldr-main/  c
cldr/  supplemental-c
3 Canonicalizing Locale Strings
locale->available-cldr-locale
locale->cldr-locale
locale->cldr-language
locale->cldr-region
locale->cldr-script
cldr-locale
6.3.90.900

CLDR Core

Jon Zeppieri <zeppieri@gmail.com>

CLDR is the Common Locale Data Repository, a database of localization information published by the Unicode Consortium.

The CLDR Core library is a Racket interface to the cldr-core JSON distribution published by the Unicode Consortium.

This package provides functions for:
  • enumerating the set of locales supported by CLDR and testing whether a given locale is supported;

  • accessing CLDR JSON data; and

  • canonicalizing locale strings and mapping them to the set of supported CLDR locales.

 (require cldr/core) package: cldr-core

1 Locale Support

procedure

(all-locales)  (listof string?)

Returns the list of locales supported by CLDR

procedure

(modern-locales)  (listof string?)

Returns the list of modern locales supported by CLDR.

procedure

(locale? loc)  boolean?

  loc : string?
Returns #t if loc is in (all-locales), #f otherwise.

Examples:
> (locale? "fr")

#t

> (locale? "yi")

#t

procedure

(modern-locale? loc)  boolean?

  loc : string?
Returns #t if loc is in (moderns-locales), #f otherwise.

Examples:
> (modern-locale? "fr")

#t

> (modern-locale? "yi")

#f

procedure

(available-locales)  jsexpr?

Returns the raw data from the availableLocales.json data file.

2 Accessing CLDR JSON Data

procedure

(cldr-ref data key [fail])  any/c

  data : jsexpr?
  key : cldr-key/c
  fail : any/c = 
(λ ()
  (raise (exn:fail:contract ....)))
Looks up the mapping of key in data. If there is no such mapping, then fail determines the result:

procedure

(cldr-ref* data [#:fail fail] key ...)  any/c

  data : jsexpr?
  fail : any/c = 
(λ ()
  (raise (exn:fail:contract ....)))
  key : cldr-key/c
Like cldr-ref, except that any number of keys may be provided. The keys are tried in order, and the value of the first key to be found is returned. If none of the given keys are mapped in data, then fail is used to determine the result, just as in cldr-ref.

procedure

(cldr-json path-to-zipfile    
  package-name    
  path-within-zipfile    
  common-prefix)  jsexpr?
  path-to-zipfile : path?
  package-name : string?
  path-within-zipfile : path?
  common-prefix : cldr-key/c
A low-level procedure for accessing raw CLDR data from .zip files. This function is useful for implementing packages within the cldr collection but is generally not useful for users of those packages.

In order to keep download sizes reasonable (since the CLDR data set is very large), packages in the cldr collection keep their data in a .zip file named for the package in question. For example, the cldr-core package contains a data file named cldr-core.zip. This file is a compressed archive of the official distribution.

The cldr-json procedure takes:

procedure

(raise-locale-not-found locale    
  package-name)  any/c
  locale : string?
  package-name : string?
Raises exn:cldr:locale-not-found, indicating that locale is not available in the CLDR data set for the package named by package-name.

This function is useful for authors of packages within the cldr collection.

struct

(struct exn:cldr exn:fail ()
    #:transparent)
A struct type that serves as the base type for all CLDR errors.

struct

(struct exn:cldr:locale-not-found exn:cldr (locale pkg)
    #:transparent)
  locale : string?
  pkg : string?
Raised by functions that are given locale strings that cannot be mapped to CLDR locales.

value

cldr-key/c : flat-contract?

A contract for lookup keys used by cldr-ref and cldr-ref*. The contract is defined as:

(or/c symbol? string? integer?
      (listof (or/c symbol? string? integer?)))

value

cldr-main/c : chaperone-contract?

A contract for functions that return raw data from the main section of the CLDR dataset. Data in the main section is per-locale. The contract is defined as:

(-> string? jsexpr?)

The string argument is a locale name.

value

cldr/supplemental-c : chaperone-contract?

A contract for functions that return raw data from the supplemental section of the CLDR dataset. Data in the supplemental section is not distributed in a per-locale manner. This contract is defined as:

(-> jsexpr?)

3 Canonicalizing Locale Strings

 (require cldr/likely-subtags) package: cldr-core

This module provides a high-level interface to the data in likelySubtags.json, described in the CLDR specification.

procedure

(locale->available-cldr-locale locale    
  available?)  string?
  locale : string?
  available? : (-> string? boolean?)
Returns the best available CLDR locale string corresponding to the given CLDR string. Availability is determined by the given available? predicate.

Examples:

procedure

(locale->cldr-locale locale)  cldr-locale?

  locale : string?
Returns the cldr-locale that best matches the given locale string.

Examples:
> (locale->cldr-locale "en")

(cldr-locale "en" "Latn" "US")

> (locale->cldr-locale "ar")

(cldr-locale "ar" "Arab" "EG")

> (locale->cldr-locale "zh")

(cldr-locale "zh" "Hans" "CN")

procedure

(locale->cldr-language locale)  string?

  locale : string?
Returns the CLDR language code that best matches the given locale string. Equivalent to (cldr-locale-lang (locale->cldr-locale locale)).

procedure

(locale->cldr-region locale)  string?

  locale : string?
Returns the CLDR region code that best matches the given locale string. Equivalent to (cldr-locale-region (locale->cldr-locale locale)).

procedure

(locale->cldr-script locale)  string?

  locale : string?
Returns the CLDR script code that best matches the given locale string. Equivalent to (cldr-locale-script (locale->cldr-locale locale)).

struct

(struct cldr-locale (lang script region)
    #:transparent)
  lang : string?
  script : string?
  region : string?