mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-15 05:36:11 +01:00
feat: server side strings
This commit is contained in:
1 parent
bdabadcd49
commit
44203223fd
9 files changed
+76
-105
No files matched your search
@@ -1,15 +1,42 @@
|
||||
import type { CatalogItemAccessor } from "@blitzkit/closed";
|
||||
import type { Strings } from "@blitzkit/i18n";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import type { Tank } from "../../protos/tank";
|
||||
import type { TankList } from "../../protos/tank_list";
|
||||
import type { Tanks } from "../../protos/tanks";
|
||||
|
||||
export abstract class AbstractAPI {
|
||||
abstract tanks(): Promise<Tanks>;
|
||||
|
||||
abstract tankList(): Promise<TankList>;
|
||||
|
||||
abstract strings(
|
||||
abstract _strings(locale: string): Promise<Strings>;
|
||||
abstract _gameStrings(
|
||||
locale: string,
|
||||
prefix?: string
|
||||
prefix: string
|
||||
): Promise<Record<string, string>>;
|
||||
|
||||
private assertLocale(locale: string) {
|
||||
const supported = locales.supported.find(
|
||||
(supported) => supported.locale === locale
|
||||
);
|
||||
|
||||
if (supported === undefined) {
|
||||
throw new Error(`Unsupported locale: ${locale}`);
|
||||
}
|
||||
|
||||
return supported;
|
||||
}
|
||||
async strings(locale: string) {
|
||||
this.assertLocale(locale);
|
||||
return await this._strings(locale);
|
||||
}
|
||||
async gameStrings(locale: string, prefix: string) {
|
||||
const supported = this.assertLocale(locale);
|
||||
const blitz = supported.blitz ?? supported.locale;
|
||||
return await this._gameStrings(blitz, prefix);
|
||||
}
|
||||
|
||||
abstract tank(id: string): Promise<Tank>;
|
||||
|
||||
abstract avatars(): Promise<CatalogItemAccessor[]>;
|
||||
|
||||
Reference in new issue
Block a user