Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadLocalizationFromPOFile(locale, poFileContent) {
const localization = gettextParser.po.parse(poFileContent);
// addLocale(locale, removeEmptyTranslations(localization));
addLocale(locale, localization);
return localization;
}
export function addTranslationsToTTag(translations: Translations[]) {
const localesToUse: Locale[] = [];
// register with ttag
for (const t of translations) {
const locale = localeFromString(t.headers.language);
addLocale(locale.string, t);
localesToUse.push(locale);
}
console.log('Available locales:', localesToUse.map(l => l.string));
// set locale in ttag
useLocales(localesToUse.map(locale => locale.string));
// update active locales
// we need to modify the actual array content, so that all imported references get the changes
currentLocales.splice(0, currentLocales.length);
currentLocales.push(...localesToUse);
}
const { t, ngettext, msgid, addLocale, useLocale } = require('ttag');
const locale = process.env.LOCALE;
if (locale) {
const translationObj = require(`./${locale}.po.json`);
addLocale(locale, translationObj);
useLocale(locale);
}
function startCount(n) {
console.log(t`starting count up to ${n}`);
for (let i = 0; i <= n; i++) {
console.log(ngettext(msgid`${i} tick passed`, `${i} ticks passed`, i));
}
}
startCount(3);
export function changeLocale(locale: string) {
console.log(locale);
const translationObj = getTranslationObj(locale);
addLocale(locale, translationObj);
useLocale(locale);
}
import { addLocale, useLocale } from 'ttag';
if (process.env.NODE_ENV !== 'production') {
const ukLocale = require('./uk.po');
addLocale('uk', ukLocale);
useLocale('uk');
}