labels-manager
v0.3.7
Published
This is a very simple library you can use to manage your multilanguage in your app.
Downloads
19
Readme
This is a very simple library you can use to manage your multilanguage in your app.
Usage
- Installation
npm i labels-manager
- Create a file with a name like '[locale].json' with the following format and put it in the public/labels sample name it-IT.json
{
"demo": {
"label_01": "Demo Label 01",
"label_02": "Demo Label 02"
},
"anotherContext": {}
}
- Import
import { LanguageManager } from 'labels-manager';
- Load your language (this should be done once an saved in your app state, or update just if you want to reload the labels or change language)
const [labels, setLabels] = useState({});
LanguageManager.loadLabels('it-IT').then(response => {
setLabels(response);
})
.catch(err => {
console.log("Problem loading the Site Labels");
});
- Show a label in code
const [value, setValue] = useState(true);
const label = value ? 'demo.label_01' : 'demo.label_02';
...
{LanguageManager.getLabel(labels, label, 'default_ demoLabel')}
Available Scripts
In the project directory, you can run:
npm start
Runs the Demo app in the development mode. Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits. You will also see any lint errors in the console.
npm run distribute
Builds (made for windows) the app for production to the dist
folder.
It correctly bundles the React component.
npm publish
Publish the dist on npmjs.