Changed .localize method to need mandatory translations to be passed as second parameter

This commit is contained in:
Alexander Cerutti
2021-10-18 00:43:53 +02:00
parent be8d524ad3
commit 547045076a
3 changed files with 47 additions and 13 deletions

View File

@@ -669,8 +669,8 @@ export default class PKPass extends Bundle {
// ************************** //
/**
* Allows to specify a language to be added to the
* final bundle, along with some optionals translations.
* Allows to add a localization details to the
* final bundle with some translations.
*
* If the language already exists, translations will be
* merged with the existing ones.
@@ -685,11 +685,11 @@ export default class PKPass extends Bundle {
public localize(
lang: string,
translations?: { [key: string]: string } | null,
translations: { [key: string]: string } | null,
) {
if (typeof lang !== "string") {
throw new TypeError(
formatMessage(Messages.LANGUAGES.INVALID_TYPE, typeof lang),
formatMessage(Messages.LANGUAGES.INVALID_LANG, typeof lang),
);
}
@@ -698,6 +698,13 @@ export default class PKPass extends Bundle {
return;
}
if (!translations || !Object.keys(translations).length) {
console.warn(
formatMessage(Messages.LANGUAGES.NO_TRANSLATIONS, lang),
);
return;
}
this[localizationSymbol][lang] ??= {};
if (typeof translations === "object" && !Array.isArray(translations)) {