Skip to content

Instantly share code, notes, and snippets.

@AlexMost
Created January 12, 2018 11:20
Show Gist options
  • Save AlexMost/556b65724ce3aade04f1a9ea5b183ff9 to your computer and use it in GitHub Desktop.
Save AlexMost/556b65724ce3aade04f1a9ea5b183ff9 to your computer and use it in GitHub Desktop.
import { t, addLocale, useLocale } from 'c-3po';
import gettextParser from 'gettext-parser';
import fs from 'fs';
const locale = process.env.LOCALE; // let's desice that locale is passed through ENV
if (locale) {
// parsing po file with gettext-parser and applying translations
const translationObj = gettextParser.po.parse(
fs.readFileSync(`${locale}.po`).toString()
);
addLocale(locale, translationObj);
useLocale(locale);
}
const name = 'c-3po';
t`Hello ${ name }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment