0.2.11 • Published 1 year ago
@volley/solid-localization v0.2.11
@volley/solid-localization
This library provides easy localization support for @volley/solid & @volley/solid-gev voice-skills.
Installation
> npm i @volley/solid-localization
@volley/solid-gev Skills
If you're using @volley/solid-gev follow these steps.
Configuration
Install the supplied GEV localization plugin:
import { plugin as localizationPlugin } from "@volley/localization";
// in your GEV plugin setup
[
// ...
localizationPlugin,
// ...
];
Pass the session container to installCopy()
and bind your ILocaleProvider
:
import {
AlexaLocaleLens,
installCopy,
tokens as localeTokens,
ILocaleProvider,
} from "@volley/solid-localization";
// in your session startup
installCopy(container);
container // allow AlexaLocaleLens to resolve the Engine
.bind(localeTokens.Engine)
.to($);
container.bind(ILocaleProvider).to(AlexaLocaleLens);
Usage
Define a copy service:
import { injectable } from "inversify";
import { BaseCopyService } from "@volley/solid-localization";
@injectable()
class IntroCopy extends BaseCopyService<IntroCopy> {
["en-US"] = "Welcome to the Alexa Skills Kit, you can say hello!" as const;
["de-DE"] =
"Willkommen bei der Alexa Fähigkeiten Kit, du kannst Hallo sagen!" as const;
}
Use the copy service:
import { Copy, copy } from "@volley/solid-localization";
class IntroScene {
@copy(IntroCopy)
protected introCopy!: Copy<IntroCopy>;
say(copy: string) {
console.log(copy);
}
async enter() {
this.say(this.introCopy);
}
}
this.introCopy
will automatically resolve to the correct localization for the user's locale.