Skip to content

Commit

Permalink
Docs: Fix code output placement
Browse files Browse the repository at this point in the history
Fixes #313
Closes #412
  • Loading branch information
Juan Soto authored and rxaviers committed Mar 12, 2015
1 parent 1c0f98b commit de67b82
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 90 deletions.
95 changes: 69 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,17 @@ to you in different flavors):
Return a function that formats a date according to the given `pattern`.

```javascript
.dateFormatter( "GyMMMd" )( new Date() ) ➡ "Nov 30, 2010 AD"
.dateFormatter({ date: "medium" })( new Date() ) ➡ "Nov 1, 2010"
.dateFormatter({ time: "medium" })( new Date() ) ➡ "5:55:00 PM"
.dateFormatter({ datetime: "medium" })( new Date() ) ➡ "Nov 1, 2010, 5:55:00 PM"
.dateFormatter( "GyMMMd" )( new Date() )
// > "Nov 30, 2010 AD"

.dateFormatter({ date: "medium" })( new Date() )
// > "Nov 1, 2010"

.dateFormatter({ time: "medium" })( new Date() )
// > "5:55:00 PM"

.dateFormatter({ datetime: "medium" })( new Date() )
// > "Nov 1, 2010, 5:55:00 PM"
```

[Read more...](doc/api/date/date-formatter.md)
Expand All @@ -292,10 +299,17 @@ to you in different flavors):
Return a function that parses a string date according to the given `pattern`.

```javascript
.dateParser( "GyMMMd" )( "Nov 30, 2010 AD" ) ➡ new Date()
.dateParser({ date: "medium" })( "Nov 1, 2010" ) ➡ new Date()
.dateParser({ time: "medium" })( "5:55:00 PM" ) ➡ new Date()
.dateParser({ datetime: "medium" })( "Nov 1, 2010, 5:55:00 PM" ) ➡ new Date()
.dateParser( "GyMMMd" )( "Nov 30, 2010 AD" )
// > new Date()

.dateParser({ date: "medium" })( "Nov 1, 2010" )
// > new Date()

.dateParser({ time: "medium" })( "5:55:00 PM" )
// > new Date()

.dateParser({ datetime: "medium" })( "Nov 1, 2010, 5:55:00 PM" )
// > new Date()
```

[Read more...](doc/api/date/date-parser.md)
Expand Down Expand Up @@ -323,8 +337,11 @@ to you in different flavors):
pluralization and gender inflections.

```javascript
.messageFormatter( "task" )( 1000 ) ➡ "You have 1,000 tasks remaining"
.messageFormatter( "like" )( 3 ) ➡ "You and 2 others liked this"
.messageFormatter( "task" )( 1000 )
// > "You have 1,000 tasks remaining"

.messageFormatter( "like" )( 3 )
// > "You and 2 others liked this"
```

[Read more...](doc/api/message/message-formatter.md)
Expand All @@ -340,11 +357,20 @@ to you in different flavors):
Return a function that formats a number according to the given options or locale's defaults.

```javascript
.numberFormatter()( pi ) ➡ "3.142"
.numberFormatter({ maximumFractionDigits: 5 })( pi ) ➡ "3.14159"
.numberFormatter({ round: "floor" })( pi ) ➡ "3.141"
.numberFormatter({ minimumFractionDigits: 2 })( 10000 ) ➡ "10,000.00"
.numberFormatter({ style: "percent" })( 0.5 ) ➡ "50%"
.numberFormatter()( pi )
// > "3.142"

.numberFormatter({ maximumFractionDigits: 5 })( pi )
// > "3.14159"

.numberFormatter({ round: "floor" })( pi )
// > "3.141"

.numberFormatter({ minimumFractionDigits: 2 })( 10000 )
// > "10,000.00"

.numberFormatter({ style: "percent" })( 0.5 )
// > "50%"
```

[Read more...](doc/api/number/number-formatter.md)
Expand All @@ -355,9 +381,14 @@ to you in different flavors):
locale's defaults.

```javascript
.numberParser()( "3.14159" ) ➡ 3.14159
.numberParser()( "10,000.00" ) ➡ 10000
.numberParser({ style: "percent" })( "50%" ) ➡ 0.5
.numberParser()( "3.14159" )
// > 3.14159

.numberParser()( "10,000.00" )
// > 10000

.numberParser({ style: "percent" })( "50%" )
// > 0.5
```

[Read more...](doc/api/number/number-parser.md)
Expand All @@ -378,11 +409,20 @@ to you in different flavors):
locale's defaults.

```javascript
.currencyFormatter( "USD" )( 1 ) ➡ "$1.00"
.currencyFormatter( "USD", { style: "accounting" })( -1 ) ➡ "($1.00)"
.currencyFormatter( "USD", { style: "name" })( 69900 ) ➡ "69,900.00 US dollars"
.currencyFormatter( "USD", { style: "code" })( 69900 ) ➡ "69,900.00 USD"
.currencyFormatter( "USD", { round: "ceil" })( 1.491 ) ➡ "$1.50"
.currencyFormatter( "USD" )( 1 )
// > "$1.00"

.currencyFormatter( "USD", { style: "accounting" })( -1 )
// > "($1.00)"

.currencyFormatter( "USD", { style: "name" })( 69900 )
// > "69,900.00 US dollars"

.currencyFormatter( "USD", { style: "code" })( 69900 )
// > "69,900.00 USD"

.currencyFormatter( "USD", { round: "ceil" })( 1.491 )
// > "$1.50"
```

[Read more...](doc/api/currency/currency-formatter.md)
Expand All @@ -399,8 +439,11 @@ to you in different flavors):
`one`, `two`, `few`, `many`, or `other`.

```javascript
.pluralGenerator()( 0 ) ➡ "other"
.pluralGenerator()( 1 ) ➡ "one"
.pluralGenerator()( 0 )
// > "other"

.pluralGenerator()( 1 )
// > "one"
```

[Read more...](doc/api/plural/plural-generator.md)
Expand Down Expand Up @@ -466,7 +509,7 @@ to you in different flavors):

Thrown when plural module is needed, but not loaded, eg. to format currencies
using the named form.

[Read more...](doc/error/e-missing-plural-module.md)

- **`E_UNSUPPORTED`**
Expand Down
8 changes: 6 additions & 2 deletions doc/api/core/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ var en = new Globalize( "en" );
// You can optionally omit the `new` operator.
var pt = Globalize( "pt" );

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

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

```
2 changes: 1 addition & 1 deletion doc/api/core/locale.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Globalize.locale( "pt" );

// Get default locale.
Globalize.locale();
// {
// > {
// attributes: {
// "languageId": "pt",
// "maxLanguageId": "pt_Latn_BR",
Expand Down
30 changes: 21 additions & 9 deletions doc/api/currency/currency-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ var formatter;
Globalize.locale( "en" );
formatter = Globalize.currencyFormatter( "USD" );

formatter( 9.99 ); // "$9.99"
formatter( 9.99 );
// > "$9.99"

```

You can use the instance method `.currencyFormatter()`, which uses the instance
Expand All @@ -56,8 +58,12 @@ locale.
var deFormatter = Globalize( "de" ).currencyFormatter( "EUR" ),
zhFormatter = Globalize( "zh" ).currencyFormatter( "EUR" );

deFormatter( 9.99 ); // "9,99 €"
zhFormatter( 9.99 ); // "€ 9.99"
deFormatter( 9.99 );
// > "9,99 €"

zhFormatter( 9.99 );
// > "€ 9.99"

```

For comparison, follow the formatting output of different symbols in different
Expand All @@ -79,7 +85,8 @@ var formatter Globalize( "en" ).currencyFormatter( "USD", {
style: "accounting"
});

formatter( -1 ); // "($1.00)"
formatter( -1 );
// > "($1.00)"
```

For plural messages, use `style: "name"`.
Expand All @@ -89,8 +96,11 @@ var formatter = Globalize( "en" ).currencyFormatter( "USD", {
style: "name"
});

formatter( 0 ); // "0.00 US dollars"
formatter( 1 ); // "1.00 US dollar"
formatter( 0 );
// > "0.00 US dollars"

formatter( 1 );
// > "1.00 US dollar"
```

For comparison, follow the formatting output of different symbols in different
Expand All @@ -114,7 +124,7 @@ var formatter = Globalize( "en" ).currencyFormatter( "USD", {
});

formatter( 9.99 );
// "9.99 USD"
// > "9.99 USD"
```

Override the number of digits, grouping separators, rounding function or any
Expand All @@ -129,13 +139,15 @@ formatter = Globalize.currencyFormatter( "USD", {
style: "name"
});

formatter( 1 ); // "1 US dollar"
formatter( 1 );
// > "1 US dollar"

formatter = Globalize.currencyFormatter( "USD", {
round: "ceil"
});

formatter( 1.491 ); // "$1.50"
formatter( 1.491 );
// > "$1.50"
```

For improved performance on iterations, first create the formatter. Then, reuse
Expand Down
25 changes: 16 additions & 9 deletions doc/api/date/date-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ String value indicating a skeleton, eg. `"GyMMMd"`.
> only [date
> field](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)
> information, and in a canonical order. For example:
>
>
> | locale | `"GyMMMd"` skeleton |
> | --- | --- |
> | *en* | `"Apr 9, 2014 AD"` |
Expand All @@ -35,15 +35,15 @@ Or, a JSON object including one of the following.
>
> **date**
> One of the following String values: `full`, `long`, `medium`, or `short`, eg.
> `{ date: "full" }`.
> `{ date: "full" }`.
>
> **time**
>
>
> One of the following String values: `full`, `long`, `medium`, or `short`, eg.
> `{ time: "full" }`.
>
> **datetime**
>
>
> One of the following String values: `full`, `long`, `medium`, or `short`, eg.
> `{ datetime: "full" }`
>
Expand Down Expand Up @@ -81,7 +81,8 @@ var formatter;
Globalize.locale( "en" );
formatter = Globalize.dateFormatter({ datetime: "short" });

formatter( new Date( 2010, 10, 30, 17, 55 ) ); // "11/30/10, 5:55 PM"
formatter( new Date( 2010, 10, 30, 17, 55 ) );
// > "11/30/10, 5:55 PM"
```

You can use the instance method `.dateFormatter()`, which uses the instance locale.
Expand All @@ -90,8 +91,11 @@ You can use the instance method `.dateFormatter()`, which uses the instance loca
var enFormatter = Globalize( "en" ).dateFormatter({ datetime: "short" }),
deFormatter = Globalize( "de" ).dateFormatter({ datetime: "short" });

enFormatter( new Date( 2010, 10, 30, 17, 55 ) ); // "11/30/10, 5:55 PM"
deFormatter( new Date( 2010, 10, 30, 17, 55 ) ); // "30.11.10 17:55"
enFormatter( new Date( 2010, 10, 30, 17, 55 ) );
// > "11/30/10, 5:55 PM"

deFormatter( new Date( 2010, 10, 30, 17, 55 ) );
// > "30.11.10 17:55"
```

For comparison, follow the same formatter using different locales.
Expand Down Expand Up @@ -133,8 +137,11 @@ var globalize = Globalize( "en" ),
monthDayFormatter = globalize.dateFormatter( "MMMd" ),
hourMinuteSecondFormatter = globalize.dateFormatter( "Hms" );

monthDayFormatter( date ); // "Nov 30"
hourMinuteSecondFormatter( date ); // "17:55:00"
monthDayFormatter( date );
// > "Nov 30"

hourMinuteSecondFormatter( date );
// > "17:55:00"
```

For improved performance on iterations, first create the formatter. Then, reuse
Expand Down
6 changes: 3 additions & 3 deletions doc/api/date/date-parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Globalize.locale( "en" );
parser = Globalize.dateParser({ date: short });

parser( "1/2/13" );
// Wed Jan 02 2013 00:00:00
// > Wed Jan 02 2013 00:00:00

Globalize.locale( "es" );
parser = Globalize.dateParser({ date: short });

parser( "1/2/13" );
// Fri Feb 01 2013 00:00:00
// > Fri Feb 01 2013 00:00:00
```

You can use the instance method `.dateParser()`, which uses the instance locale.
Expand All @@ -51,7 +51,7 @@ You can use the instance method `.dateParser()`, which uses the instance locale.
var esParser = Globalize( "es" ).dateParser({ date: short });

esParser( "1/2/13" );
// Fri Feb 01 2013 00:00:00
// > Fri Feb 01 2013 00:00:00
```

For improved performance on iterations, first create the parser. Then, reuse it
Expand Down
23 changes: 16 additions & 7 deletions doc/api/message/load-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Globalize.loadMessages({
});

Globalize( "pt" ).formatMessage( "greetings/hello" );
Olá
// > Olá
```

#### Multiline strings
Expand All @@ -65,7 +65,7 @@ Globalize.loadMessages({
});

Globalize( "en" ).formatMessage( "longText" );
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi non quis exercitationem culpa nesciunt nihil aut nostrum explicabo reprehenderit optio amet ab temporibus asperiores quasi cupiditate. Voluptatum ducimus voluptates voluptas?"
// > "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi non quis exercitationem culpa nesciunt nihil aut nostrum explicabo reprehenderit optio amet ab temporibus asperiores quasi cupiditate. Voluptatum ducimus voluptates voluptas?"
```

#### Messages inheritance
Expand All @@ -87,11 +87,20 @@ Globalize.loadMessages({
"pt-PT": {}
});

Globalize( "de" ).formatMessage( "amen" ); // "Amen"
Globalize( "en" ).formatMessage( "amen" ); // "Amen"
Globalize( "en-GB" ).formatMessage( "amen" ); // "Amen"
Globalize( "fr" ).formatMessage( "amen" ); // "Amen"
Globalize( "pt-PT" ).formatMessage( "amen" ); // "Amém"
Globalize( "de" ).formatMessage( "amen" );
// > "Amen"

Globalize( "en" ).formatMessage( "amen" );
// > "Amen"

Globalize( "en-GB" ).formatMessage( "amen" );
// > "Amen"

Globalize( "fr" ).formatMessage( "amen" );
// > "Amen"

Globalize( "pt-PT" ).formatMessage( "amen" );
// > "Amém"
```

Note that `de`, `en`, `en-GB`, `fr`, and `pt-PT` are empty. `.formatMessage()`
Expand Down
Loading

0 comments on commit de67b82

Please sign in to comment.