Integrate actual translations into integration tests

This commit is contained in:
Chi Vinh Le
2018-08-29 17:01:26 +02:00
parent 0b3a67601c
commit a99fe3c0ff
24 changed files with 972 additions and 78 deletions
@@ -0,0 +1,27 @@
import { FluentBundle } from "fluent/compat";
import fs from "fs";
import path from "path";
// These locale prefixes are always loaded.
const commonPrefixes = ["common", "framework"];
function createFluentBundle(
target: string,
pathToLocale: string
): FluentBundle {
const bundle = new FluentBundle("en-US");
const files = fs.readdirSync(pathToLocale);
const prefixes = commonPrefixes.concat(target);
files.forEach(f => {
prefixes.forEach(prefix => {
if (f.startsWith(prefix)) {
bundle.addMessages(
fs.readFileSync(path.resolve(pathToLocale, f)).toString()
);
}
});
});
return bundle;
}
export default createFluentBundle;
@@ -2,3 +2,5 @@ export {
default as createRelayEnvironment,
CreateRelayEnvironmentParams,
} from "./createRelayEnvironment";
export { default as createFluentBundle } from "./createFluentBundle";