Created
January 12, 2018 11:20
-
-
Save AlexMost/556b65724ce3aade04f1a9ea5b183ff9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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