mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
Added localize method to register translation in the class; Added _generateStringFile method to create pass.string Buffer
This commit is contained in:
20
index.js
20
index.js
@@ -17,6 +17,7 @@ class Pass {
|
|||||||
this.overrides = this.options.overrides || {};
|
this.overrides = this.options.overrides || {};
|
||||||
this.Certificates = {};
|
this.Certificates = {};
|
||||||
this.model = "";
|
this.model = "";
|
||||||
|
this.l10n = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +51,7 @@ class Pass {
|
|||||||
let bundle = noDynList.filter(f => !f.includes(".lproj"));
|
let bundle = noDynList.filter(f => !f.includes(".lproj"));
|
||||||
|
|
||||||
// Localization folders only
|
// Localization folders only
|
||||||
const L10N = noDynList.filter(f => f.includes(".lproj"));
|
const L10N = noDynList.filter(f => f.includes(".lproj") && Object.keys(this.l10n).includes(path.parse(f).name));
|
||||||
|
|
||||||
let _passExtractor = (() => {
|
let _passExtractor = (() => {
|
||||||
return readFile(path.resolve(this.model, "pass.json"))
|
return readFile(path.resolve(this.model, "pass.json"))
|
||||||
@@ -107,6 +108,23 @@ class Pass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
localize(lang, translations) {
|
||||||
|
this.l10n[lang] = translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
_generateStringFile(lang) {
|
||||||
|
if (this.l10n[lang] === undefined || !Object.keys(this.l10n[lang]).length) {
|
||||||
|
return Buffer.from("", "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
let strings = Object.keys(this.l10n[lang]).map(key => `"${key}" = "${this.l10n[lang][key]}";`);
|
||||||
|
return Buffer.from(strings.join("\n"), "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks if pass model type is one of the supported ones
|
Checks if pass model type is one of the supported ones
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user