mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Added localize with translations to null to delete also files
This commit is contained in:
@@ -659,12 +659,18 @@ describe("PKPass", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should delete a language and its all translations when null is passed as parameter", () => {
|
it("should delete a language, all of its translations and all of its files, when null is passed as parameter", () => {
|
||||||
|
pass.addBuffer("it.lproj/icon@3x.png", Buffer.alloc(0));
|
||||||
|
pass.addBuffer("en.lproj/icon@3x.png", Buffer.alloc(0));
|
||||||
|
|
||||||
pass.localize("it", null);
|
pass.localize("it", null);
|
||||||
pass.localize("en", null);
|
pass.localize("en", null);
|
||||||
|
|
||||||
expect(pass[localizationSymbol]["it"]).toBeUndefined();
|
expect(pass[localizationSymbol]["it"]).toBeUndefined();
|
||||||
expect(pass[localizationSymbol]["en"]).toBeUndefined();
|
expect(pass[localizationSymbol]["en"]).toBeUndefined();
|
||||||
|
|
||||||
|
expect(pass[filesSymbol]["it.lproj/icon@3x.png"]).toBeUndefined();
|
||||||
|
expect(pass[filesSymbol]["en.lproj/icon@3x.png"]).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should always return undefined", () => {
|
it("should always return undefined", () => {
|
||||||
|
|||||||
@@ -675,8 +675,8 @@ export default class PKPass extends Bundle {
|
|||||||
* If the language already exists, translations will be
|
* If the language already exists, translations will be
|
||||||
* merged with the existing ones.
|
* merged with the existing ones.
|
||||||
*
|
*
|
||||||
* Setting `translations` to `null`, fully deletes a language
|
* Setting `translations` to `null`, fully deletes a language,
|
||||||
* and its translations.
|
* its translations and its files.
|
||||||
*
|
*
|
||||||
* @see https://developer.apple.com/documentation/walletpasses/creating_the_source_for_a_pass#3736718
|
* @see https://developer.apple.com/documentation/walletpasses/creating_the_source_for_a_pass#3736718
|
||||||
* @param lang
|
* @param lang
|
||||||
@@ -695,6 +695,20 @@ export default class PKPass extends Bundle {
|
|||||||
|
|
||||||
if (translations === null) {
|
if (translations === null) {
|
||||||
delete this[localizationSymbol][lang];
|
delete this[localizationSymbol][lang];
|
||||||
|
|
||||||
|
const allFilesKeys = Object.keys(this[filesSymbol]);
|
||||||
|
const langFolderIdentifier = `${lang}.lproj`;
|
||||||
|
|
||||||
|
for (
|
||||||
|
let i = allFilesKeys.length, filePath: string;
|
||||||
|
(filePath = allFilesKeys[--i]);
|
||||||
|
|
||||||
|
) {
|
||||||
|
if (filePath.startsWith(langFolderIdentifier)) {
|
||||||
|
delete this[filesSymbol][filePath];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user