How to use the @fluent/bundle/compat.FluentResource function in @fluent/bundle

To help you get started, we’ve selected a few @fluent/bundle 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 / client / framework / testHelpers / createFluentBundle.ts View on Github external
prefixes.forEach(prefix => {
      if (f.startsWith(prefix)) {
        // eslint-disable-next-line @typescript-eslint/no-var-requires
        bundle.addResource(
          new FluentResource(require(path.resolve(pathToLocale, f)))
        );
      }
    });
  });
github coralproject / talk / src / core / client / framework / lib / i18n / generateBundles.ts View on Github external
export default async function generateBundles(
  locales: ReadonlyArray,
  data: LocalesData
): Promise {
  const promises = [];

  for (const locale of locales) {
    // `useIsolating: false` will remove bidi characters.
    // https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation
    // We should be able to use `<bdi>` tags instead to support rtl languages.
    const bundle = new FluentBundle(locale, { functions, useIsolating: false });
    if (locale in data.bundled) {
      bundle.addResource(new FluentResource(data.bundled[locale]));
      promises.push(decorateWarnMissing(bundle));
    } else if (locale in data.loadables) {
      const content = await data.loadables[locale]();
      bundle.addResource(new FluentResource(content));
      promises.push(decorateWarnMissing(bundle));
    } else {
      throw Error(`Locale ${locale} not available`);
    }
  }

  return await Promise.all(promises);
}
</bdi>
github coralproject / talk / src / core / client / framework / lib / i18n / generateBundles.ts View on Github external
locales: ReadonlyArray,
  data: LocalesData
): Promise {
  const promises = [];

  for (const locale of locales) {
    // `useIsolating: false` will remove bidi characters.
    // https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation
    // We should be able to use `<bdi>` tags instead to support rtl languages.
    const bundle = new FluentBundle(locale, { functions, useIsolating: false });
    if (locale in data.bundled) {
      bundle.addResource(new FluentResource(data.bundled[locale]));
      promises.push(decorateWarnMissing(bundle));
    } else if (locale in data.loadables) {
      const content = await data.loadables[locale]();
      bundle.addResource(new FluentResource(content));
      promises.push(decorateWarnMissing(bundle));
    } else {
      throw Error(`Locale ${locale} not available`);
    }
  }

  return await Promise.all(promises);
}
</bdi>
github coralproject / talk / src / core / server / services / i18n / index.ts View on Github external
// `useIsolating: false` will remove bidi characters.
          // https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation
          // We should be able to use `<bdi>` tags instead to support rtl languages.
          this.bundles[locale] ||
          new FluentBundle(locale, { useIsolating: false });

        // Load all the translations in the folder.
        const files = await fs.readdir(path.join(localesFolder, folder));

        for (const file of files) {
          const filePath = path.join(localesFolder, folder, file);
          logger.debug({ locale, filePath }, "loading messages for locale");

          const messages = await fs.readFile(filePath, "utf8");

          bundle.addResource(new FluentResource(messages));
        }

        this.bundles[locale] = bundle;
      }
    }
  }
</bdi>