From 4ec86415bfb768f2bbfb388bfd67d8decdaee850 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Thu, 11 Jul 2019 23:31:48 +0200 Subject: [PATCH] Fixed problem with localization files path/fileNames --- src/parser.ts | 10 +++++++--- src/pass.ts | 17 +++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 0ba4912..6e5a6e3 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -48,11 +48,12 @@ export async function getModelContents(model: FactoryOptions["model"]) { export async function getModelFolderContents(model: string): Promise { 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 { 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] }; }) ); });