Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chlbri/internationalization
For internationalization
https://github.com/chlbri/internationalization
Last synced: 26 days ago
JSON representation
For internationalization
- Host: GitHub
- URL: https://github.com/chlbri/internationalization
- Owner: chlbri
- Created: 2022-02-25T10:58:58.000Z (almost 3 years ago)
- Default Branch: dev
- Last Pushed: 2022-03-02T12:42:42.000Z (almost 3 years ago)
- Last Synced: 2024-05-31T15:30:40.378Z (7 months ago)
- Language: TypeScript
- Size: 1.33 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
V 0.1.1 _Make it browserify_
## Just one class...
# Internationalization
## Defaut walkthrough
### First create the object with paths (like path.resolve(root, ...parts)) :
```typescript
const internationalization = new Internationalization(); // {cwd}/src/locales
const internationalization = new Internationalization(
'my',
'locales',
'directory',
); // Path is resolved with process.cwd() as root
```#### NB
1. The default path is {cwd}/src/locales
2. The locale must have at least a directory (
locales/**{locale}**/common.json )
3. The locales must be json and can be namespaces (
_locales/en/firstPage/header.json_ )
### You can init translations sync
```typescript
const internationalization = new Internationalization();
internationalization.initSync();
```
### Or async
```typescript
const internationalization = new Internationalization(
'my',
'locales',
'directory',
);
await internationalization.init();
```
### Then, you can get the string by method : getKey
```typescript
const internationalization = new Internationalization();
internationalization.initSync();
internationalization.getKey('title'); // => Title of the page
```
## Add-ons
### Change Language : changeLanguage
By default language is set to English ('en')
```typescript
const internationalization = new Internationalization();
internationalization.initSync();
internationalization.getKey('title'); // => Title of the page
internationalization.changeLanguage('fr');
internationalization.getKey('title'); // => Titre de la page
```
### Change Default Language : Internationalization.defaultLanguage
By default language is set to English ('en')
```typescript
Internationalization.defaultLanguage = 'fr';
const internationalization = new Internationalization();
internationalization.initSync();
internationalization.getKey('title'); // => Titre de la page
```
For tests, go to repo,
[here](https://github.com/chlbri/internationalization.git)
## Happy coding 😊❤️😊👨💻❤️✅!!