Fixed problem with localization files path/fileNames

This commit is contained in:
Alexander Cerutti
2019-07-11 23:31:48 +02:00
parent 6ce2b9ab22
commit 4ec86415bf
2 changed files with 16 additions and 11 deletions

View File

@@ -48,11 +48,12 @@ export async function getModelContents(model: FactoryOptions["model"]) {
export async function getModelFolderContents(model: string): Promise<PartitionedBundle> {
try {
const modelPath = path.resolve(model) + (!!model && !path.extname(model) ? ".pass" : "");
const modelPath = model + (!path.extname(model) && ".pass");
const modelFilesList = await readDir(modelPath);
// No dot-starting files, manifest and signature
const filteredFiles = removeHidden(modelFilesList).filter(f => !/(manifest|signature)/i.test(f));
const filteredFiles = removeHidden(modelFilesList)
.filter(f => !/(manifest|signature)/i.test(f) && /.+$/.test(path.parse(f).ext));
const isModelInitialized = (
filteredFiles.length &&
@@ -103,7 +104,10 @@ export async function getModelFolderContents(model: string): Promise<Partitioned
return acc;
}
return { ...acc, [file]: buffers[index] };
const fileComponents = file.split(path.sep);
const fileName = fileComponents[fileComponents.length-1];
return { ...acc, [fileName]: buffers[index] };
}, {})
);
});

View File

@@ -145,6 +145,7 @@ export class Pass {
Object.keys(this.l10nTranslations).forEach(lang => {
const strings = generateStringFile(this.l10nTranslations[lang]);
const langInBundles = `${lang}.lproj`;
if (strings.length) {
/**
@@ -153,17 +154,17 @@ export class Pass {
* it otherwise.
*/
if (!this.l10nBundles[lang]) {
this.l10nBundles[lang] = {};
if (!this.l10nBundles[langInBundles]) {
this.l10nBundles[langInBundles] = {};
}
this.l10nBundles[lang]["pass.strings"] = Buffer.concat([
this.l10nBundles[lang]["pass.strings"] || Buffer.alloc(0),
this.l10nBundles[langInBundles]["pass.strings"] = Buffer.concat([
this.l10nBundles[langInBundles]["pass.strings"] || Buffer.alloc(0),
strings
]);
}
if (!(this.l10nBundles[lang] && Object.keys(this.l10nBundles[lang]).length)) {
if (!(this.l10nBundles[langInBundles] && Object.keys(this.l10nBundles[langInBundles]).length)) {
return;
}
@@ -175,10 +176,10 @@ export class Pass {
* composition.
*/
Object.assign(finalBundle, ...Object.keys(this.l10nBundles[lang])
Object.assign(finalBundle, ...Object.keys(this.l10nBundles[langInBundles])
.map(fileName => {
const fullPath = path.join(`${lang}.lproj`, fileName).replace(/\\/, "/");
return { [fullPath]: this.l10nBundles[lang][fileName] };
const fullPath = path.join(langInBundles, fileName).replace(/\\/, "/");
return { [fullPath]: this.l10nBundles[langInBundles][fileName] };
})
);
});