Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chlbri/internationalization

For internationalization
https://github.com/chlbri/internationalization

Last synced: 26 days ago
JSON representation

For internationalization

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 😊❤️😊👨‍💻❤️✅!!