9.0
top
← prev up next →

CLDR CoreπŸ”— i

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.

1Locale SupportπŸ”— i

procedure

( all-locales )(listofstring? )

Returns the list of locales supported by CLDR

procedure

( modern-locales )(listofstring? )

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.

2Accessing CLDR JSON DataπŸ”— i

procedure

( cldr-ref datakey[fail])any/c

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

  • 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[#:failfail]key...)any/c

data:jsexpr?
fail : any/c =
(λ ()
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:

  • 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

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.

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

#: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:

(listof(or/csymbol? 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? )

3Canonicalizing Locale StringsπŸ”— i

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

procedure

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:

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

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

(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 (langscriptregion)
#:transparent)
lang:string?
script:string?
region:string?
top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /