Skip to content

Commit 0eacc1c

Browse files
author
Simon Planinschek
committed
Updated description and example in readme.md
1 parent 76a906b commit 0eacc1c

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

readme.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Internationalization
33

44
[![npm version](https://badge.fury.io/js/%40aboutbits%2Finternationalization.svg)](https://badge.fury.io/js/%40aboutbits%2Finternationalization)
55

6-
This package includes utilities for working with different languages in the browser.
6+
This package includes utilities for working with different languages in the browser.
7+
This package works for client side rendered applications as well as for server side rendered applications.
78

89
## Table of content
910

@@ -22,15 +23,26 @@ npm install @aboutbits/internationalization
2223
Second, you can setup the tool with all supported languages and the fallback language and then detect the given browser language.
2324

2425
```js
25-
import Internationalization from '@aboutbits/internationalization'
26+
import { Internationalization } from '@aboutbits/internationalization'
2627

2728
let supportedLanguages = ['en', 'de', 'it']
2829
let fallbackLanguage = 'en'
2930

3031
let i18n = new Internationalization(supportedLanguages, fallbackLanguage)
3132

32-
let language = i18n.detectBrowserLanguage()
33+
// Fetches the language only from the user's browser
34+
let browserLanguage = i18n.detectBrowserLanguage()
3335

36+
// First check the cookies to see if a language is set. If not it will look in the browser.
37+
// You can also pass a requiest obejct with which the language can be recognized already during the server side rendering
38+
let language = i18n.detectLanguage()
39+
40+
// Sets a cookie with the specified language.
41+
// There exists also a static version of this method.
42+
// Ex. Internationalization.setLanguage("de")
43+
i18n.setLanguage("de")
44+
45+
console.log(browserLanguage)
3446
console.log(language)
3547
```
3648

0 commit comments

Comments
 (0)