Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Style changes #737

Merged
merged 1 commit into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
723 changes: 278 additions & 445 deletions README.md

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions doc/api/core/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

Create a Globalize instance.

**locale|cldr**
### Parameters

Locale string or [Cldr instance](https://github.com/rxaviers/cldrjs) of the
instance.
#### locale|cldr

Locale string or [Cldr instance](https://github.com/rxaviers/cldrjs) of the instance.

### Example

Prior to creating any Globalize instance, you must load
`cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more
information.
Prior to creating any Globalize instance, you must load `cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more information.

[CLDR content]: ../../../README.md#2-cldr-content

Expand All @@ -26,5 +25,4 @@ en.formatNumber( 3.1415 );

pt.formatNumber( 3.1415 );
// > 3,142

```
11 changes: 4 additions & 7 deletions doc/api/core/load.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
## Globalize.load( cldrJSONData, ... )

This method allows you to load CLDR JSON locale data. `Globalize.load()` is a
proxy to `Cldr.load()`.
This method allows you to load CLDR JSON locale data. `Globalize.load()` is a proxy to `Cldr.load()`.

This method can be called as many time as needed. All passed JSON objects are
deeply merged internally.
This method can be called as many time as needed. All passed JSON objects are deeply merged internally.

For more information, see https://github.com/rxaviers/cldrjs#readme.

### Parameters

**cldrJSONData**
#### cldrJSONData

A JSON object with CLDR data. See [Getting Started](#../../../README.md#2-cldr-content)
for more information.
A JSON object with CLDR data. See [Getting Started](#../../../README.md#2-cldr-content) for more information.

### Example

Expand Down
23 changes: 6 additions & 17 deletions doc/api/core/locale.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,22 @@ Set default locale, or get it if locale argument is omitted.

Return the default [Cldr instance](https://github.com/rxaviers/cldrjs).

An application that supports globalization and/or localization will need to
have a way to determine the user's preference. Attempting to automatically
determine the appropriate locale is useful, but it is good practice to always
offer the user a choice, by whatever means.
An application that supports globalization and/or localization will need to have a way to determine the user's preference. Attempting to automatically determine the appropriate locale is useful, but it is good practice to always offer the user a choice, by whatever means.

Whatever your mechanism, it is likely that you will have to correlate the
user's preferences with the list of locale data supported in the app. This
method allows you to select the best match given the locale data that you
have included and to set the Globalize locale to the one which the user
prefers.
Whatever your mechanism, it is likely that you will have to correlate the user's preferences with the list of locale data supported in the app. This method allows you to select the best match given the locale data that you have included and to set the Globalize locale to the one which the user prefers.

LanguageMatching TBD (CLDR's spec http://www.unicode.org/reports/tr35/#LanguageMatching).

### Parameters

**locale|cldr**
#### locale|cldr

The locale string, eg. `en`, `pt-BR`, or `zh-Hant-TW`. Or,

The [Cldr instance](https://github.com/rxaviers/cldrjs), eg. new
`Cldr( "en" )`.
- The locale string, e.g., `"en"`, `"pt-BR"`, or `"zh-Hant-TW"`. Or,
- The [Cldr instance](https://github.com/rxaviers/cldrjs), e.g., new `Cldr( "en" )`.

### Example

Prior to using this function, you must load
`cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more
information.
Prior to using this function, you must load `cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more information.

[CLDR content]: ../../../README.md#2-cldr-content

Expand Down
78 changes: 29 additions & 49 deletions doc/api/currency/currency-formatter.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
## .currencyFormatter( currency [, options] ) ➜ function( value )

Return a function that formats a `currency` according to the given `options` or
locale's defaults.
Return a function that formats a `currency` according to the given `options` or locale's defaults.

The returned function is invoked with one argument: the Number `value` to be
formatted.
The returned function is invoked with one argument: the Number `value` to be formatted.

### Parameters

**currency**
#### currency

3-letter currency code as defined by ISO 4217, eg. `USD`.

**options** Optional
#### options.style

A JSON object including none or any of the following options.
Optional. String `symbol` (default), `accounting`, `code` or `name`. See [`.numberFormatter( [options] )`](../number/number-formatter.md) for more options.

> **style** Optional
>
> String `symbol` (default), `accounting`, `code` or `name`.

See [`.numberFormatter( [options] )`](../number/number-formatter.md) for more
options.

**value**
#### value

Number to be formatted, eg. `9.99`.

### Example

Prior to using any currency methods, you must load
`cldr/main/{locale}/currencies.json`, `cldr/supplemental/currencyData.json`, and
the CLDR content required by the number module. If using plural messages, you
also must load the CLDR content required by the plural module. Read [CLDR
content][] if you need more information.
Prior to using any currency methods, you must load `cldr/main/{locale}/currencies.json`, `cldr/supplemental/currencyData.json`, and the CLDR content required by the number module. If using plural messages, you also must load the CLDR content required by the plural module. Read [CLDR content][] if you need more information.

[CLDR content]: ../../../README.md#2-cldr-content

You can use the static method `Globalize.currencyFormatter()`, which uses the
default locale.
You can use the static method `Globalize.currencyFormatter()`, which uses the default locale.

```javascript
var formatter;
Expand All @@ -51,8 +37,7 @@ formatter( 9.99 );

```

You can use the instance method `.currencyFormatter()`, which uses the instance
locale.
You can use the instance method `.currencyFormatter()`, which uses the instance locale.

```javascript
var deFormatter = Globalize( "de" ).currencyFormatter( "EUR" ),
Expand All @@ -66,17 +51,16 @@ zhFormatter( 9.99 );

```

For comparison, follow the formatting output of different symbols in different
locales.
For comparison, follow the formatting output of different symbols in different locales.

| 3-letter currency code | en (English) | de (German) | zh (Chinese) |
| --- | --- | --- | --- |
| `.currencyFormatter( "USD" )( 1 )` | `$1.00` | `1,00 $` | `US$ 1.00` |
| `.currencyFormatter( "EUR" )( 1 )` | `€1.00` | `1,00 €` | `€ 1.00` |
| `.currencyFormatter( "CNY" )( 1 )` | `CN¥1.00` | `1,00 CN¥` | `¥ 1.00` |
| `.currencyFormatter( "JPY" )( 1 )` | `¥1` | `1 ¥` | `JP¥ 1` |
| `.currencyFormatter( "GBP" )( 1 )` | `£1.00` | `1,00 £` | `£ 1.00` |
| `.currencyFormatter( "BRL" )( 1 )` | `R$1.00` | `1,00 R$` | `R$ 1.00` |
| 3-letter currency code | en (English) | de (German) | zh (Chinese) |
| ---------------------------------- | ------------ | ----------- | ------------ |
| `.currencyFormatter( "USD" )( 1 )` | `$1.00` | `1,00 $` | `US$ 1.00` |
| `.currencyFormatter( "EUR" )( 1 )` | `€1.00` | `1,00 €` | `€ 1.00` |
| `.currencyFormatter( "CNY" )( 1 )` | `CN¥1.00` | `1,00 CN¥` | `¥ 1.00` |
| `.currencyFormatter( "JPY" )( 1 )` | `¥1` | `1 ¥` | `JP¥ 1` |
| `.currencyFormatter( "GBP" )( 1 )` | `£1.00` | `1,00 £` | `£ 1.00` |
| `.currencyFormatter( "BRL" )( 1 )` | `R$1.00` | `1,00 R$` | `R$ 1.00` |

For the accounting variation of the symbol format, use `style: "accounting"`.

Expand All @@ -103,18 +87,16 @@ formatter( 1 );
// > "1.00 US dollar"
```

For comparison, follow the formatting output of different symbols in different
locales using the plural messages `Globalize( locale ).currencyFormatter( currency,
{ style: "name" } )( 1 )`.
For comparison, follow the formatting output of different symbols in different locales using the plural messages `Globalize( locale ).currencyFormatter( currency, { style: "name" } )( 1 )`.

| 3-letter currency code | en (English) | de (German) | zh (Chinese) |
| --- | --- | --- | --- |
| `USD` | `1.00 US dollar` | `1,00 US-Dollar` | `1.00美元` |
| `EUR` | `1.00 euro` | `1,00 Euro` | `1.00欧元` |
| `CNY` | `1.00 Chinese yuan` | `1,00 Chinesischer Yuan` | `1.00人民币` |
| `JPY` | `1 Japanese yen` | `1 Japanischer Yen` | `1日元` |
| `GBP` | `1.00 British pound sterling` | `1,00 Britisches Pfund Sterling` | `1.00英镑` |
| `BRL` | `1.00 Brazilian real` | `1,00 Brasilianischer Real` | `1.00巴西雷亚尔` |
| 3-letter currency code | en (English) | de (German) | zh (Chinese) |
| ---------------------- | ----------------------------- | -------------------------------- | ------------ |
| `USD` | `1.00 US dollar` | `1,00 US-Dollar` | `1.00美元` |
| `EUR` | `1.00 euro` | `1,00 Euro` | `1.00欧元` |
| `CNY` | `1.00 Chinese yuan` | `1,00 Chinesischer Yuan` | `1.00人民币` |
| `JPY` | `1 Japanese yen` | `1 Japanischer Yen` | `1日元` |
| `GBP` | `1.00 British pound sterling` | `1,00 Britisches Pfund Sterling` | `1.00英镑` |
| `BRL` | `1.00 Brazilian real` | `1,00 Brasilianischer Real` | `1.00巴西雷亚尔` |

For the international currency code, use `style: "code"`.

Expand All @@ -127,8 +109,7 @@ formatter( 9.99 );
// > "9.99 USD"
```

Override the number of digits, grouping separators, rounding function or any
other [`.numberFormatter()` options](../number/number-formatter.md).
Override the number of digits, grouping separators, rounding function or any other [`.numberFormatter()` options](../number/number-formatter.md).

```javascript
var formatter;
Expand All @@ -150,8 +131,7 @@ formatter( 1.491 );
// > "$1.50"
```

For improved performance on iterations, first create the formatter. Then, reuse
it on each loop.
For improved performance on iterations, first create the formatter. Then, reuse it on each loop.

```javascript
var formatter = Globalize( "en" ).currencyFormatter( "USD" );
Expand Down
Loading