# j-Locale

> This component sets current browser locale (number format, date format and time format) according to the navigatior.language.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 3091033db97448f7ec8934ff82579a2a5db8a676f43327de1ccbb75f42b81016
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

This component sets current browser locale (number format, date format and time format) according to the `navigatior.language`.

- singleton
- `path` will contain current's browser locale
- sets `DEF.dateformat` and it creates environment value called `[ts]`

__Configuration__:

- `language {String}` optional, a custom language (default: `navigator.language`)
- `requests {Boolean}` optional, adds a language to the every request (it affects `DEF.languagehtml`, default: `false`)

__Environments__:

- `[ts]` full timestamp
- `[date]` only date
- `[time]` only time

__Output__:

```js
{
	dt: 'yyyy–MM–dd', // date format
	nf: 1,  // number format: 1 = 100 000.123, 2 = 100 000,123, 3 = 100.000,123, 4 = 100,000.123
	fdw: 0, // first day of week
	tf: 24  // time format: 12, 24
}
```

__Methods__:

- `component.use(language)`

__Supported special languages__:

- `eu` with the dd.MM.yyyy with a 24 hour system
- `us` with the MM-dd-yyyy with a 12 hour system

Use it with `<ui-component name="locale">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="locale" path="mylocale"></ui-component>
<hr />
<pre><ui-bind path="mylocale" config="text:JSON.stringify(value, null, '  ')"></ui-bind></pre>
<ui-bind path="testvalue" config="template" class="mt10 block">
	<script type="text/html">
		<div>{{ value.date | format }}</div>
		<div>{{ value.date | format('[ts]') }}</div>
		<div>{{ value.number | format(2) }}</div>
	</script>
</ui-bind>

<script>
	var testvalue = { date: new Date(), number: 1234567.89 };
</script>
```
