This commit is contained in:
David Štaleker
2025-07-18 05:33:16 +02:00
parent 401a367e5d
commit db0cc8d3de
14776 changed files with 9251484 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
## .attributes
Attributes is an Object created during instance initialization (construction), and are used internally by `.get()` to replace dynamic parts of an item path.
| Attribute | Field |
| --- | --- |
| `language` | Language Subtag ([spec](http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions)) |
| `script` | Script Subtag ([spec](http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions)) |
| `region` or `territory` | Region Subtag ([spec](http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions)) |
| `languageId` | Language Id ([spec](http://www.unicode.org/reports/tr35/#Unicode_language_identifier)) |
| `maxLanguageId` | Maximized Language Id ([spec](http://www.unicode.org/reports/tr35/#Likely_Subtags)) |
- `language`, `script`, `territory` (also aliased as `region`), and `maxLanguageId` are computed by [adding likely subtags](./src/likely-subtags.js) according to the [specification](http://www.unicode.org/reports/tr35/#Likely_Subtags).
- `languageId` is always in the succint form, obtained by [removing the likely subtags from `maxLanguageId`](./src/remove-likely-subtags.js) according to the [specification](http://www.unicode.org/reports/tr35/#Likely_Subtags).

View File

@@ -0,0 +1,9 @@
## new Cldr( locale )
Create a new instance of Cldr.
| Parameter | Type | Example |
| --- | --- | --- |
| *locale* | String | `"en"`, `"pt-BR"` |
More information in the [specification](http://www.unicode.org/reports/tr35/#Locale).

View File

@@ -0,0 +1,18 @@
## .get( path )
Get the item data given its path, or `undefined` if missing.
| Parameter | Type | Example |
| --- | --- | --- |
| *path* | String or<br>Array | `"/cldr/main/{languageId}/numbers/symbols-numberSystem-latn/decimal"`<br>`[ "cldr", "main", "{languageId}", "numbers", "symbols-numberSystem-latn", "decimal" ]` |
On *path* parameter, note the leading "/cldr" can be ommited. Also, note that its Array form accepts subpaths, eg. `[ "cldr/main", "{languageId}", "numbers/symbols-numberSystem-latn/"decimal" ]`.
The [locale attributes](#cldrattributes), eg. `{languageId}`, are replaced with their appropriate values.
If extended with the `cldr/unresolved.js` module, get the item data or lookup by following [locale inheritance](http://www.unicode.org/reports/tr35/#Locale_Inheritance), set a local resolved cache if it's found (for subsequent faster access), or return `undefined`.
```javascript
ptBr.get( "main/{languageId}/numbers/symbols-numberSystem-latn/decimal" );
// ➡ ","
```

View File

@@ -0,0 +1,23 @@
## Cldr.load( json, ... )
Load resolved or unresolved [1] JSON data.
| Parameter | Type | Description |
| --- | --- | --- |
| *json* | Object | Resolved or unresolved [1] CLDR JSON data |
```javascript
Cldr.load({
"main": {
"pt-BR": {
"numbers": {
"symbols-numberSystem-latn": {
"decimal": ","
}
}
}
}
});
```
1: Unresolved processing is **only available** after loading `cldr/unresolved.js` extension module.

View File

@@ -0,0 +1,12 @@
## .main( path )
It's an alias for `.get([ "main/{languageId}", ... ])`.
| Parameter | Type | Example |
| --- | --- | --- |
| *path* | String or<br>Array | See `cldr.get()` for more information |
```javascript
ptBr.main( "numbers/symbols-numberSystem-latn/decimal" );
// ➡ ","
```

View File

@@ -0,0 +1,10 @@
## get ➡ ( path, value )
Triggered before a `.get()` (or any alias) return. The triggered listener receives the normalized *path* and the *value* found.
| Parameter | Description |
| --- | --- |
| *path* | See [../core/get.md](.get()) for more information |
| *value* | See [../core/get.md](.get()) for more information |
See [Cldr.on()](global_on.md) or [.on()](on.md) for example.

View File

@@ -0,0 +1,10 @@
## Cldr.off( event, listener )
Removes a listener function from the specified event globally (for all instances).
| Parameter | Type | Example |
| --- | --- | --- |
| *event* | String | `"get"` |
| *listener* | Function | |
See [Cldr.on()](global_on.md) for example.

View File

@@ -0,0 +1,32 @@
## Cldr.on( event, listener )
Add a listener function to the specified event globally (for all instances).
| Parameter | Type | Example |
| --- | --- | --- |
| *event* | String | `"get"` |
| *listener* | Function | |
```javascript
Cldr.load({
foo: "bar"
});
function log( path, value ) {
console.log( "Got", path, value );
}
Cldr.on( "get", log );
en = new Cldr( "en" );
en.get( "foo" );
// Got foo bar (logged)
// ➡ bar
zh = new Cldr( "zh" );
zh.get( "foo" );
// Got foo bar (logged)
// ➡ bar
Cldr.off( "get", log );
```

View File

@@ -0,0 +1,28 @@
## Cldr.once( event, listener )
Add a listener function to the specified event globally (for all instances). It will be automatically removed after it's first execution.
| Parameter | Type | Example |
| --- | --- | --- |
| *event* | String | `"get"` |
| *listener* | Function | |
```javascript
Cldr.load({
foo: "bar"
});
function log( path, value ) {
console.log( "Got", path, value );
}
Cldr.once( "get", log );
cldr = new Cldr( "en" );
cldr.get( "foo" );
// Got foo bar (logged)
// ➡ bar
cldr.get( "foo" );
// ➡ bar
```

View File

@@ -0,0 +1,10 @@
## .off( event, listener )
Removes a listener function from the specified event for this instance.
| Parameter | Type | Example |
| --- | --- | --- |
| *event* | String | `"get"` |
| *listener* | Function | |
See [cldr.on()](on.md) for example.

View File

@@ -0,0 +1,26 @@
## .on( event, listener )
Add a listener function to the specified event for this instance.
| Parameter | Type | Example |
| --- | --- | --- |
| *event* | String | `"get"` |
| *listener* | Function | |
```javascript
Cldr.load({
foo: "bar"
});
function log( path, value ) {
console.log( "Got", path, value );
}
cldr = new Cldr( "en" );
cldr.on( "get", log );
cldr.get( "foo" );
// Got foo bar (logged)
// ➡ bar
cldr.off( "get", log );
```

View File

@@ -0,0 +1,27 @@
## .once( event, listener )
Add a listener function to the specified event for this instance. It will be automatically removed after it's first execution.
| Parameter | Type | Example |
| --- | --- | --- |
| *event* | String | `"get"` |
| *listener* | Function | |
```javascript
Cldr.load({
foo: "bar"
});
function log( path, value ) {
console.log( "Got", path, value );
}
cldr = new Cldr( "en" );
cldr.once( "get", log );
cldr.get( "foo" );
// Got foo bar (logged)
// ➡ bar
cldr.get( "foo" );
// ➡ bar
```

View File

@@ -0,0 +1,12 @@
## .supplemental( path )
It's an alias for `.get([ "supplemental", ... ])`.
| Parameter | Type | Example |
| --- | --- | --- |
| *path* | String or<br>Array | See `cldr.get()` for more information |
```javascript
en.supplemental( "gender/personList/{language}" );
// ➡ "neutral"
```

View File

@@ -0,0 +1,8 @@
## .supplemental.timeData.allowed()
Helper function. Return the supplemental timeData allowed of locale's territory.
```javascript
en.supplemental.timeData.allowed();
// ➡ "H h"
```

View File

@@ -0,0 +1,8 @@
## .supplemental.timeData.preferred()
Helper function. Return the supplemental timeData preferred of locale's territory.
```javascript
en.supplemental.timeData.preferred();
// ➡ "h"
```

View File

@@ -0,0 +1,8 @@
## .supplemental.weekData.firstDay()
Helper function. Return the supplemental weekData firstDay of locale's territory.
```javascript
en.supplemental.weekData.firstDay();
// ➡ "sun"
```

View File

@@ -0,0 +1,8 @@
## .supplemental.weekData.minDays()
Helper function. Return the supplemental weekData minDays of locale's territory as a Number.
```javascript
en.supplemental.weekData.minDays();
// ➡ 1
```

View File

@@ -0,0 +1,12 @@
## .get( path )
Overload (extend) `.get()` to get the item data or lookup by following [locale inheritance](http://www.unicode.org/reports/tr35/#Locale_Inheritance), set a local resolved cache if it's found (for subsequent faster access), or return `undefined`.
| Parameter | Type | Example |
| --- | --- | --- |
| *path* | String or<br>Array | See `cldr.get()` above for more information |
```javascript
ptBr.get( "main/{languageId}/numbers/symbols-numberSystem-latn/decimal" );
// ➡ ","
```