Renamed splitBundle to splitBufferBundle and edited it to return splitted l10n/rootBundle object

This commit is contained in:
Alexander Cerutti
2019-07-11 23:29:23 +02:00
parent ef4ce53dd6
commit 92a48eccbe
2 changed files with 18 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import moment from "moment";
import { EOL } from "os";
import { BundleUnit } from "./schema";
import { PartitionedBundle } from "./schema";
import { sep } from "path";
/**
* Checks if an rgb value is compliant with CSS-like syntax
@@ -88,11 +89,19 @@ export function generateStringFile(lang: { [index: string]: string }): Buffer {
* @param origin
*/
export function splitBundle(origin: Object): [BundleUnit, BundleUnit] {
export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundle"], PartitionedBundle["bundle"]] {
const keys = Object.keys(origin);
return keys.reduce(([ l10n, bundle ], current) =>
current.includes(".lproj") &&
[ { ...l10n, [current]: origin[current] }, bundle] ||
[ l10n, {...bundle, [current]: origin[current] }]
, [{},{}]);
return keys.reduce(([ l10n, bundle ], current) => {
if (current.includes(".lproj")) {
const pathComponents = current.split(sep);
const lang = pathComponents[0];
const file = pathComponents.slice(1).join("/");
(l10n[lang] || (l10n[lang] = {}))[file] = origin[current];
return [ l10n, bundle ];
} else {
return [ l10n, { ...bundle, [current]: origin[current] }];
}
}, [{},{}]);
}