Skip to content

aboutbits/internationalization

Repository files navigation

Internationalization

npm package license

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

Usage

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.

import { Internationalization } from '@aboutbits/internationalization'

let supportedLanguages = ['en', 'de', 'it']
let fallbackLanguage = 'en'

let i18n = new Internationalization(supportedLanguages, fallbackLanguage)

// Fetches the language only from the user's browser
let browserLanguage = i18n.detectBrowserLanguage()

// 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 rendering
let language = i18n.detectLanguage()

// Sets a cookie with the specified language. 
// There exists also a static version of this method. 
// Ex. Internationalization.setLanguage("de")
i18n.setLanguage("de")

console.log(browserLanguage)
console.log(language)

Build & Publish

To build and publish the package, visit the GitHub Actions page of the repository.

You can choose between two workflows:

  • Release Package to publish a new version of the package.
  • Pre-Release Package to publish a new pre-release version of the package.

Note: Pre-releases need to be supplied with a pre-id.

Note: To increment a pre-release, you have to run the normal release workflow and select "prerelease". For this action you need to already be on a pre-release version.

Information

About Bits is a company based in South Tyrol, Italy. You can find more information about us on our website.

Support

For support, please contact [email protected].

Credits

License

The MIT License (MIT). Please see the license file for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5