CLDR Core
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.
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?)
procedure
(modern-locales) → (listof string?)
procedure
(modern-locale? loc) → boolean?
loc : string?
> (modern-locale? "fr") #t
> (modern-locale? "yi") #f
procedure
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 ....)))
If fail is a procedure, it is called (through a tail call) with no arguments to produce the result.
Otherwise, fail is returned as the result.
procedure
(cldr-ref* data [#:fail fail] key ...) → any/c
data : jsexpr?
fail : any/c =
(λ () (raise (exn:fail:contract ....))) key : cldr-key/c
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
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:
the path to this zipfile (typically defined within the package using define-runtime-path);
the name of the package (which doubles as the name of the zipfile, without the .zip extension);
the path within the zipfile to the desired .json file; and
a key used to prune the returned JSON data.
procedure
(raise-locale-not-found locale package-name) → any/c locale : string? package-name : string?
This function is useful for authors of packages within the cldr collection.
struct
(struct exn:cldr:locale-not-found exn:cldr (locale pkg) #:transparent) locale : string? pkg : string?
(or/c symbol? string? integer? (listof (or/c symbol? string? integer?)))
value
cldr-main/c : chaperone-contract?
The string argument is a locale name.
(-> 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?)
> (locale->available-cldr-locale "gd" locale?) "gd"
> (locale->available-cldr-locale "gd" modern-locale?) "root"
procedure
(locale->cldr-locale locale) → cldr-locale?
locale : string?
> (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?
procedure
(locale->cldr-region locale) → string?
locale : string?
procedure
(locale->cldr-script locale) → string?
locale : string?
struct
(struct cldr-locale (lang script region) #:transparent) lang : string? script : string? region : string?