0.0.3 • Published 4 years ago
l10n-doctor v0.0.3
L10N Doctor
This library is still in PoC stage, and it's not ready for production. Feel free to share your ideas. If you want to contribute. Please keep your pull requests small, and understandable.
L10N Doctor is a simple localization library for your JavaScript application.
Install
yarn add l10n-doctor
or
npm install --save l10n-doctor
Usage
Example usage in the browser:
browser.ts
import { ContentRepository } from 'l10n-doctor';
const contentRepository = new ContentRepository({ accessKey: L10N_DR_TOKEN });
contentRepository.getContentBundle('en_gb').then(contentBundle => {
document.body.innerHTML = `<h1>${contentBundle.getText('Hello World!', { cId: 'hello_world' })}</h1>`;
});
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example App</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Eample usage in an express app:
server.ts
import express from 'express';
const app = express();
import { ContentRepository } from 'l10n-doctor';
const contentRepository = new ContentRepository({ accessKey: L10N_DR_TOKEN });
contentRepository.getContentBundle('en_gb').then(contentBundle => {
app.get('*', (req, res) => {
res.send(`<!DOCTYPE html>
<html lang="en">
<head>
<title>Example App</title>
</head>
<body>
<h1>${contentBundle.getText('Hello World!', { cId: 'hello_world' })}</h1>
</body>
</html>`)
});
app.listen(PORT, () => console.log(`App is listening on ${PORT} 3000`));
});
Server Response
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example App</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Upcoming features
getText()
will automatically create ContentElements if they don't exist yetgetText()
to allow using parametersgetElement()
will return<span data-cId="hello_world">Hello World!</span>
for convenient integration with in-context editor.
License
MIT © sleepingevil