mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 20:25:26 +00:00
Added languages getter
This commit is contained in:
@@ -8,8 +8,6 @@ import { app } from "./webserver";
|
||||
import { getCertificates } from "./shared";
|
||||
import path from "path";
|
||||
import { PKPass } from "passkit-generator";
|
||||
/** Symbols are exported just for tests and examples. Replicate only if really needed. */
|
||||
import { localizationSymbol } from "passkit-generator/lib/PKPass";
|
||||
|
||||
app.route("/localize/:modelName").get(async (request, response) => {
|
||||
const passName =
|
||||
@@ -51,10 +49,7 @@ app.route("/localize/:modelName").get(async (request, response) => {
|
||||
// This language does not exist but is still added as .lproj folder
|
||||
pass.localize("zu", {});
|
||||
|
||||
console.log(
|
||||
"Added languages",
|
||||
Object.keys(pass[localizationSymbol]).join(", "),
|
||||
);
|
||||
console.log("Added languages", Object.keys(pass.languages).join(", "));
|
||||
|
||||
const stream = pass.getAsStream();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { finish400WithoutModelName, createPassGenerator } from "../shared";
|
||||
import type { ALBEvent, ALBResult } from "aws-lambda";
|
||||
import type { PKPass } from "passkit-generator";
|
||||
import { localizationSymbol } from "passkit-generator/lib/PKPass";
|
||||
|
||||
/**
|
||||
* Lambda for localize example
|
||||
@@ -36,10 +35,7 @@ export async function localize(event: ALBEvent) {
|
||||
LOCATION: "plassering",
|
||||
});
|
||||
|
||||
console.log(
|
||||
"Added languages",
|
||||
Object.keys(pass[localizationSymbol]).join(", "),
|
||||
);
|
||||
console.log("Added languages", Object.keys(pass.languages).join(", "));
|
||||
|
||||
return (await passGenerator.next(pass as PKPass)).value as ALBResult;
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ describe("PKPass", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("certificates setter", () => {
|
||||
describe("certificates", () => {
|
||||
it("should throw an error if certificates provided are not complete or invalid", () => {
|
||||
expect(() => {
|
||||
// @ts-expect-error
|
||||
@@ -583,6 +583,47 @@ describe("PKPass", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("languages", () => {
|
||||
it("should get updated when translations gets added through localize", () => {
|
||||
expect(pass.languages.length).toBe(0);
|
||||
expect(pass.languages).toEqual([]);
|
||||
|
||||
pass.localize("en", {
|
||||
buon_giorno: "Good Morning",
|
||||
buona_sera: "Good Evening",
|
||||
});
|
||||
|
||||
expect(pass.languages.length).toBe(1);
|
||||
expect(pass.languages).toEqual(["en"]);
|
||||
});
|
||||
|
||||
it("should get updated when translations are added through .addBuffer", () => {
|
||||
const validTranslationStringsEN = `
|
||||
/* Insert Element menu item */
|
||||
"Insert Element" = "Insert Element";
|
||||
/* Error string used for unknown error types. */
|
||||
"ErrorString_1" = "An unknown error occurred.";
|
||||
`;
|
||||
|
||||
pass.addBuffer(
|
||||
"en.lproj/pass.strings",
|
||||
Buffer.from(validTranslationStringsEN),
|
||||
);
|
||||
|
||||
const validTranslationStringsIT = `
|
||||
"Insert Element" = "Inserisci elemento";
|
||||
"ErrorString_1" = "Un errore sconosciuto è accaduto";
|
||||
`;
|
||||
|
||||
pass.addBuffer(
|
||||
"it.lproj/pass.strings",
|
||||
Buffer.from(validTranslationStringsIT),
|
||||
);
|
||||
|
||||
expect(pass.languages).toEqual(["en", "it"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("localize", () => {
|
||||
it("should fail throw if lang is not a string", () => {
|
||||
// @ts-expect-error
|
||||
|
||||
@@ -179,6 +179,14 @@ export default class PKPass extends Bundle {
|
||||
this[certificatesSymbol] = certs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows retrieving current languages
|
||||
*/
|
||||
|
||||
public get languages() {
|
||||
return Object.keys(this[localizationSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows getting an image of the props
|
||||
* that are composing your pass instance.
|
||||
|
||||
Reference in New Issue
Block a user