mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 22:25:24 +00:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import {
|
|
throwClientErrorWithoutModelName,
|
|
createPassGenerator,
|
|
} from "../shared";
|
|
import type { ALBEvent, ALBResult } from "aws-lambda";
|
|
import type { PKPass } from "passkit-generator";
|
|
|
|
/**
|
|
* Lambda for localize example
|
|
*/
|
|
|
|
export async function localize(event: ALBEvent) {
|
|
try {
|
|
throwClientErrorWithoutModelName(event);
|
|
} catch (err) {
|
|
return err;
|
|
}
|
|
|
|
const { modelName, ...passOptions } = event.queryStringParameters;
|
|
|
|
const passGenerator = createPassGenerator(modelName, passOptions);
|
|
|
|
const pass = (await passGenerator.next()).value as PKPass;
|
|
|
|
/**
|
|
* Italian and German already has an .lproj which gets included
|
|
* but it doesn't have translations
|
|
*/
|
|
pass.localize("it", {
|
|
EVENT: "Evento",
|
|
LOCATION: "Dove",
|
|
});
|
|
|
|
pass.localize("de", {
|
|
EVENT: "Ereignis",
|
|
LOCATION: "Ort",
|
|
});
|
|
|
|
// ...while Norwegian doesn't, so it gets created
|
|
pass.localize("nn", {
|
|
EVENT: "Begivenhet",
|
|
LOCATION: "plassering",
|
|
});
|
|
|
|
console.log("Added languages", Object.keys(pass.languages).join(", "));
|
|
|
|
return (await passGenerator.next(pass as PKPass)).value as ALBResult;
|
|
}
|