How to use the ttag.addLocale function in ttag

To help you get started, we’ve selected a few ttag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sozialhelden / wheelmap-frontend / test / specs / generateScreenshots.js View on Github external
function loadLocalizationFromPOFile(locale, poFileContent) {
  const localization = gettextParser.po.parse(poFileContent);
  // addLocale(locale, removeEmptyTranslations(localization));
  addLocale(locale, localization);
  return localization;
}
github sozialhelden / wheelmap-frontend / src / lib / i18n.js View on Github external
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);
}
github ttag-org / ttag / examples / quickstart / counter.js View on Github external
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);
github zzorba / ArkhamCards / app / i18n.ts View on Github external
export function changeLocale(locale: string) {
  console.log(locale);
  const translationObj = getTranslationObj(locale);
  addLocale(locale, translationObj);
  useLocale(locale);
}
github ttag-org / ttag / examples / webpack-setup / localeSetup.js View on Github external
import { addLocale, useLocale } from 'ttag';

if (process.env.NODE_ENV !== 'production') {
    const ukLocale = require('./uk.po');
    addLocale('uk', ukLocale);
    useLocale('uk');
}

ttag

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://stand-with-ukraine.pp.ua)

MIT
Latest version published 6 months ago

Package Health Score

70 / 100
Full package analysis