drop legacy enum from ts/
This commit is contained in:
parent
2e704660d6
commit
0de7ab87a5
@ -17,18 +17,6 @@ class Variable(TypedDict):
|
|||||||
kind: Literal["Any", "Int", "String", "Float"]
|
kind: Literal["Any", "Int", "String", "Float"]
|
||||||
|
|
||||||
|
|
||||||
def legacy_enum() -> str:
|
|
||||||
out = ["export enum LegacyEnum {"]
|
|
||||||
for module in modules:
|
|
||||||
for translation in module["translations"]:
|
|
||||||
key = stringcase.constcase(translation["key"])
|
|
||||||
value = module["index"] * 1000 + translation["index"]
|
|
||||||
out.append(f" {key} = {value},")
|
|
||||||
|
|
||||||
out.append("}")
|
|
||||||
return "\n".join(out) + "\n"
|
|
||||||
|
|
||||||
|
|
||||||
def methods() -> str:
|
def methods() -> str:
|
||||||
out = [
|
out = [
|
||||||
"export class GeneratedTranslations {",
|
"export class GeneratedTranslations {",
|
||||||
@ -93,7 +81,6 @@ def typescript_arg_name(arg: Variable) -> str:
|
|||||||
|
|
||||||
out = ""
|
out = ""
|
||||||
|
|
||||||
out += legacy_enum()
|
|
||||||
out += methods()
|
out += methods()
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import "intl-pluralrules";
|
import "intl-pluralrules";
|
||||||
import { FluentBundle, FluentResource, FluentNumber } from "@fluent/bundle/compat";
|
import { FluentBundle, FluentResource, FluentNumber } from "@fluent/bundle/compat";
|
||||||
import { LegacyEnum, GeneratedTranslations } from "anki/i18n_generated";
|
import { GeneratedTranslations } from "anki/i18n_generated";
|
||||||
|
|
||||||
type RecordVal = number | string | FluentNumber;
|
type RecordVal = number | string | FluentNumber;
|
||||||
|
|
||||||
@ -23,7 +23,6 @@ function formatNumbers(args?: Record<string, RecordVal>): void {
|
|||||||
export class I18n extends GeneratedTranslations {
|
export class I18n extends GeneratedTranslations {
|
||||||
bundles: FluentBundle[] = [];
|
bundles: FluentBundle[] = [];
|
||||||
langs: string[] = [];
|
langs: string[] = [];
|
||||||
TR = LegacyEnum;
|
|
||||||
|
|
||||||
translate(key: string, args: Record<string, RecordVal>): string {
|
translate(key: string, args: Record<string, RecordVal>): string {
|
||||||
formatNumbers(args);
|
formatNumbers(args);
|
||||||
@ -36,11 +35,6 @@ export class I18n extends GeneratedTranslations {
|
|||||||
return `missing key: ${key}`;
|
return `missing key: ${key}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr(id: LegacyEnum, args?: Record<string, RecordVal>): string {
|
|
||||||
const key = this.keyName(id);
|
|
||||||
return this.translate(key, args || {});
|
|
||||||
}
|
|
||||||
|
|
||||||
supportsVerticalText(): boolean {
|
supportsVerticalText(): boolean {
|
||||||
const firstLang = this.bundles[0].locales[0];
|
const firstLang = this.bundles[0].locales[0];
|
||||||
return (
|
return (
|
||||||
@ -69,10 +63,6 @@ export class I18n extends GeneratedTranslations {
|
|||||||
weekday: "narrow",
|
weekday: "narrow",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private keyName(msg: LegacyEnum): string {
|
|
||||||
return this.TR[msg].toLowerCase().replace(/_/g, "-");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupI18n(): Promise<I18n> {
|
export async function setupI18n(): Promise<I18n> {
|
||||||
|
Loading…
Reference in New Issue
Block a user