Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)))
);
}
});
});
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>
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>
// `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>