Skip to content

Commit

Permalink
Docs: update directives
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed Dec 15, 2017
1 parent 09abf71 commit da314aa
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It allows, in addition to translation, to localize numbers and dates of your app
---

> Library version: 4.1.2 - [Changelog](https://github.com/robisim74/angular-l10n/releases)
> Library version: 4.1.3 - [Changelog](https://github.com/robisim74/angular-l10n/releases)
<br>

Expand Down Expand Up @@ -64,4 +64,4 @@ and use global `ng.l10n` namespace.
---

### AoT compilation, Server Side Rendering & strict
This library is compatible with AoT compilation & Server Side Rendering. It also supports the `strict` TypeScript compiler option.
This library is compatible with AoT compilation & [Server Side Rendering](quick-start/#appendix-d-using-angular-universal). It also supports the `strict` TypeScript compiler option.
6 changes: 3 additions & 3 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ import { Component, OnInit } from '@angular/core';
<p l10n-title title="Greeting" l10nTranslate>Subtitle</p>
<p l10nDate="fullDate">{{ today }}</p>
<p l10nDecimal="1.5-5">{{ pi }}</p>
<p l10nCurrency="1.2-2" [currencyDisplay]="'symbol'">{{ value }}</p>
<p format="fullDate" l10nDate>{{ today }}</p>
<p digits="1.5-5" l10nDecimal>{{ pi }}</p>
<p digits="1.2-2" currencyDisplay="symbol" l10nCurrency>{{ value }}</p>
<button (click)="change()" l10nTranslate>Change</button>
`
Expand Down
4 changes: 2 additions & 2 deletions docs/spec/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Method | Function
### L10nLoader
Method | Function
------ | --------
`load(): Promise<void>` |
`load(): Promise<void>` | Loads l10n services

<br>

Expand Down Expand Up @@ -127,7 +127,7 @@ Method | Function
### ILocaleValidation
Method | Function
------ | --------
`parseNumber(s: string): number | null` | Converts a string to a number according to default locale
`parseNumber(s: string): number | null` | Converts a string to a number according to default locale. If the string cannot be converted to a number, returns NaN

<br>

Expand Down
4 changes: 2 additions & 2 deletions docs/spec/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Implement `LocaleStorage` class-interface and the `read` and `write` methods:

/**
* This method must contain the logic to read the storage.
* @param name 'defaultLocale' or 'currency'
* @param name 'defaultLocale', 'currency' or 'timezone'
* @return A promise with the value of the given name
*/
public async read(name: string): Promise<string | null> {
Expand All @@ -407,7 +407,7 @@ Implement `LocaleStorage` class-interface and the `read` and `write` methods:

/**
* This method must contain the logic to write the storage.
* @param name 'defaultLocale' or 'currency'
* @param name 'defaultLocale', 'currency' or 'timezone'
* @param value The value for the given name
*/
public async write(name: string, value: string): Promise<void> {
Expand Down
29 changes: 11 additions & 18 deletions docs/spec/getting-the-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ L10nCurrency | `l10nCurrency`

Directive | Type | Format | Html syntax
--------- | ---- | ------ | -----------
Translate | Message | String | `<tag l10n-attribute attribute="expr1" l10nTranslate>expr2</tag>`
L10nDate | Date | Date/Number/ISO string | `<tag l10n-attribute attribute="expr1" l10nDate="[format]">expr2</tag>`
L10nDecimal | Decimal | Number/string | `<tag l10n-attribute attribute="expr1" l10nDecimal="[digitInfo]">expr2</tag>`
L10nPercent | Percentage | Number/string | `<tag l10n-attribute attribute="expr1" l10nPercent="[digitInfo]">expr2</tag>`
L10nCurrency | Currency | Number/string | `<tag l10n-attribute attribute="expr1" l10nCurrency="[digitInfo]" [currencyDisplay]="[currencyDisplay]">expr2</tag>`
Translate | Message | String | `<tag l10n-attribute attribute="expr1" [params]="[params]" l10nTranslate>expr2</tag>`
L10nDate | Date | Date/Number/ISO string | `<tag l10n-attribute attribute="expr1" format="[format]" l10nDate>expr2</tag>`
L10nDecimal | Decimal | Number/string | `<tag l10n-attribute attribute="expr1" digits="[digitInfo]" l10nDecimal>expr2</tag>`
L10nPercent | Percentage | Number/string | `<tag l10n-attribute attribute="expr1" digits="[digitInfo]" l10nPercent>expr2</tag>`
L10nCurrency | Currency | Number/string | `<tag l10n-attribute attribute="expr1" digits="[digitInfo]" currencyDisplay="[currencyDisplay]" l10nCurrency>expr2</tag>`

> You can dynamically change parameters and expressions values as with pipes. How does it work? To observe the expression change (not the parameters), a `MutationObserver` is used: the observer is added only if detected in the browser. If you want to use this feature also reaching older browsers, we recommend using pipes.
Expand All @@ -267,23 +267,23 @@ L10nCurrency | Currency | Number/string | `<tag l10n-attribute attribute="expr1"
<br>
##### Parameters
```Html
<p [l10nTranslate]="{ user: username, NoMessages: messages.length }">User notifications</p>
<p [params]="{ user: username, NoMessages: messages.length }" l10nTranslate>User notifications</p>
```

<br>
#### Dates & Numbers
```Html
<p l10nDate>{{ today }}</p>
<p l10nDate="fullDate">{{ today }}</p>
<p format="fullDate" l10nDate>{{ today }}</p>

<p l10nDecimal>{{ value }}</p>
<p l10nDecimal="1.5-5">{{ value }}</p>
<p digits="1.5-5" l10nDecimal>{{ value }}</p>

<p l10nPercent>{{ value }}</p>
<p l10nPercent="1.1-1">{{ value }}</p>
<p digits="1.1-1" l10nPercent>{{ value }}</p>

<p l10nCurrency>{{ value }}</p>
<p l10nCurrency="1.2-2" [currencyDisplay]="'symbol'">{{ value }}</p>
<p digits="1.2-2" currencyDisplay="symbol" l10nCurrency>{{ value }}</p>
```

<br>
Expand All @@ -295,17 +295,10 @@ All attributes will be translated according to the master directive: `l10nTransl

> You can't dynamically change expressions in attributes.
If you need to translate only the attributes and there isn't a master key to translate, you should use pipes:
```Html
<input type="text" placeholder="{{ 'Greeting' | translate:lang }}">
```

> Why? Because the master directive tries to find anyway a key to translate, walking the DOM: this may cause unexpected behavior if other translation directives are present in the subtree.
<br>
##### Parameters
```Html
<p l10n-title title="Greeting" [l10nTranslate]="{ user: username, NoMessages: messages.length }">User notifications</p>
<p l10n-title title="Greeting" [params]="{ user: username, NoMessages: messages.length }" l10nTranslate>User notifications</p>
```
_Json_:
```
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/library-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ Class | Contract
### Main class-interfaces
Class | Contract
----- | --------
`LocaleStorage` | Class-interface to create a custom storage for default locale & currency
`LocaleStorage` | Class-interface to create a custom storage for default locale, currency & timezone
`TranslationProvider` | Class-interface to create a custom provider for translation data
`TranslationHandler` | Class-interface to create a custom handler for translated values
6 changes: 3 additions & 3 deletions docs/spec/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Directive | Selectors

Directive | Validator | Options | Errors
--------- | --------- | ------- | ------
`L10nNumberValidator` | `l10nValidateNumber=[digitInfo]` | `[minValue]` `[maxValue]` | `format` or `minValue` or `maxValue`
`L10nNumberValidator` | `digits=[digitInfo]` | `[minValue]` `[maxValue]` | `format` or `minValue` or `maxValue`

where `digitInfo` has the following format: `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`, and `minValue` and `maxValue` attributes are optional:
```Html
<input l10nValidateNumber="1.2-2" [minValue]="0" [maxValue]="1000" name="decimal" [(ngModel)]="decimal">
<input digits="1.2-2" [minValue]="0" [maxValue]="1000" name="decimal" [(ngModel)]="decimal" l10nValidateNumber>
```
or, if you use variables:
```Html
<input [l10nValidateNumber]="digits" [minValue]="minValue" [maxValue]="maxValue" name="decimal" [(ngModel)]="decimal">
<input [digits]="digits" [minValue]="minValue" [maxValue]="maxValue" name="decimal" [(ngModel)]="decimal" l10nValidateNumber>
```

The number can be entered with or without the thousands separator.
Expand Down

0 comments on commit da314aa

Please sign in to comment.