https://github.com/aboutbits/internationalization
https://github.com/aboutbits/internationalization
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aboutbits/internationalization
- Owner: aboutbits
- License: mit
- Created: 2020-08-06T11:56:11.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-20T10:54:12.000Z (11 months ago)
- Last Synced: 2025-04-26T06:41:47.924Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 448 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
Internationalization
====================
[](https://badge.fury.io/js/%40aboutbits%2Finternationalization)
[](https://github.com/aboutbits/internationalization/blob/master/license.md)
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](#usage)
- [Build & Publish](#build--publish)
- [Information](#information)
## Usage
First, you have to install the package:
```bash
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.
```js
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, simply commit all changes and push them to master. Then run one of the following commands locally:
```bash
npm version patch
npm version minor
npm version major
```
## Information
About Bits is a company based in South Tyrol, Italy. You can find more information about us on [our website](https://aboutbits.it).
### Support
For support, please contact [info@aboutbits.it](mailto:info@aboutbits.it).
### Credits
- [Alex Lanz](https://github.com/alexlanz)
- [Martin Malfertheiner](https://github.com/mmalfertheiner)
- [All Contributors](../../contributors)
### License
The MIT License (MIT). Please see the [license file](license.md) for more information.