@@ -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
2223Second, 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
2728let supportedLanguages = [' en' , ' de' , ' it' ]
2829let fallbackLanguage = ' en'
2930
3031let 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)
3446console .log (language)
3547```
3648
0 commit comments