This package includes utilities for working with different languages in the browser. This package works for client side rendered applications as well as for server side rendered applications.
Table of content
First, you have to install the package:
npm install @aboutbits/internationalization
Second, you can setup the tool with all supported languages and the fallback language and then detect the given browser language.
let supportedLanguages = 'en' 'de' 'it'let fallbackLanguage = 'en'let i18n = supportedLanguages fallbackLanguage// Fetches the language only from the user's browserlet browserLanguage = i18n// First check the cookies to see if a language is set. If not it will look in the browser.// You can also pass a requiest obejct with which the language can be recognized already during the server side renderinglet language = i18n// Sets a cookie with the specified language.// There exists also a static version of this method.// Ex. Internationalization.setLanguage("de")i18nconsoleconsole
Build & Publish
To build and publish the package, simply commit all changes and push them to master. Then run one of the following commands locally:
npm version patchnpm version minornpm version major
About Bits is a company based in South Tyrol, Italy. You can find more information about us on our website.
For support, please contact firstname.lastname@example.org.
The MIT License (MIT). Please see the license file for more information.