How to use @fluent/dom - 2 common examples

To help you get started, we’ve selected a few @fluent/dom 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 coralproject / talk / src / core / server / queue / tasks / mailer / processor.ts View on Github external
return async (
    tenant: Tenant,
    templateName: string,
    locale: LanguageCode,
    fromAddress: string,
    data: MailerData
  ): Promise => {
    // Setup the localization bundles.
    const bundle = i18n.getBundle(locale);
    const loc = new DOMLocalization([], generateBundleIterator(bundle));

    // Translate the HTML fragments.
    let dom: JSDOM;
    try {
      // Parse the rendered template.
      dom = new JSDOM(data.message.html, {});
    } catch (err) {
      logger.error({ err }, "could not parse the HTML for i18n");

      throw err;
    }

    // Translate the bundle.
    await loc.translateFragment(dom.window.document);

    // Grab the rendered HTML from the dom, and juice them.
github projectfluent / fluent-web / src / index.js View on Github external
async function* generateMessages(resourceIds) {
  const locales = negotiateLanguages(
    navigator.languages,
    meta.available,
    {
      defaultLocale: meta.default,
    },
  );
  for (const locale of locales) {
    yield createContext(locale, resourceIds);
  }
}

const resourceIds = getResourceLinks(document.head);
document.l10n = new DOMLocalization(
  resourceIds, generateMessages,
);
window.addEventListener("languagechange", document.l10n);

document.l10n.ready = documentReady().then(() => {
  document.l10n.connectRoot(document.documentElement);
  return document.l10n.translateRoots();
});

@fluent/dom

Fluent bindings for DOM

Apache-2.0
Latest version published 5 months ago

Package Health Score

70 / 100
Full package analysis