@aethervtt/shard-text 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/build.d.ts +43 -0
- package/dist/build.js +106 -0
- package/dist/charset.d.ts +8 -0
- package/dist/charset.js +43 -0
- package/dist/components.d.ts +54 -0
- package/dist/components.js +118 -0
- package/dist/font.d.ts +193 -0
- package/dist/font.js +377 -0
- package/dist/importer.d.ts +40 -0
- package/dist/importer.js +193 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +140 -0
- package/dist/kerning.d.ts +8 -0
- package/dist/kerning.js +168 -0
- package/dist/layout.d.ts +84 -0
- package/dist/layout.js +297 -0
- package/dist/locale.d.ts +133 -0
- package/dist/locale.js +574 -0
- package/dist/msdf.d.ts +52 -0
- package/dist/msdf.js +1147 -0
- package/dist/opentype.d.ts +36 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +43 -0
- package/dist/preview.d.ts +2 -0
- package/dist/preview.js +76 -0
- package/dist/render.d.ts +114 -0
- package/dist/render.js +544 -0
- package/dist/shaders.d.ts +2 -0
- package/dist/shaders.js +158 -0
- package/dist/shape.d.ts +77 -0
- package/dist/shape.js +404 -0
- package/dist/source.d.ts +44 -0
- package/dist/source.js +108 -0
- package/package.json +40 -0
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { AssetStore, type ImporterDef } from '@aethervtt/shard-assets';
|
|
2
|
+
import { type ComponentDef, type Query, ShardError, type World } from '@aethervtt/shard-core';
|
|
3
|
+
import { type App, type AppMethod } from '@aethervtt/shard-runtime';
|
|
4
|
+
export declare const PLURAL_CATEGORIES: readonly ['zero', 'one', 'two', 'few', 'many', 'other'];
|
|
5
|
+
export type PluralCategory = (typeof PLURAL_CATEGORIES)[number];
|
|
6
|
+
/** One string: plain, or by plural category (`{ "one": "{n} item", "other": "{n} items" }`). */
|
|
7
|
+
export type StringEntry = string | Partial<Record<PluralCategory, string>>;
|
|
8
|
+
/** A loaded `*.strings.json`: key → string for one locale. Hot reload bumps `version`. */
|
|
9
|
+
export declare class StringTable {
|
|
10
|
+
locale: string;
|
|
11
|
+
strings: Map<string, StringEntry>;
|
|
12
|
+
version: number;
|
|
13
|
+
constructor(locale: string, strings: Map<string, StringEntry>);
|
|
14
|
+
copyFrom(other: StringTable): void;
|
|
15
|
+
}
|
|
16
|
+
export declare const StringTables: import("@aethervtt/shard-core").ResourceDef<AssetStore<StringTable, "StringTable">>;
|
|
17
|
+
export declare const StringTableAssetType: import("@aethervtt/shard-assets").AssetTypeDef<StringTable>;
|
|
18
|
+
/**
|
|
19
|
+
* The locale a table's file name names: `en.strings.json` and `hud.pt-BR.strings.json` are `en`
|
|
20
|
+
* and `pt-BR`. Undefined if the name has no valid BCP 47 tag.
|
|
21
|
+
*/
|
|
22
|
+
export declare function localeOfPath(path: string): string | undefined;
|
|
23
|
+
/** The `{name}` placeholders in an entry, sorted and deduplicated. */
|
|
24
|
+
export declare function placeholdersOf(entry: StringEntry): string[];
|
|
25
|
+
/** Every problem in a string table's JSON, each with a JSON pointer. */
|
|
26
|
+
export declare function validateStringTable(json: unknown): ShardError[];
|
|
27
|
+
/** `*.strings.json`: one locale's strings, named by the locale (`locales/pt-BR.strings.json`). */
|
|
28
|
+
export declare const StringTableImporter: ImporterDef;
|
|
29
|
+
export declare const stringTableSchema: () => unknown;
|
|
30
|
+
export interface LocaleValue {
|
|
31
|
+
/** BCP 47 tag, e.g. `pt-BR`. */
|
|
32
|
+
current: string;
|
|
33
|
+
/** The last locale tried: `pt-BR` falls back to `pt`, then this. */
|
|
34
|
+
fallback: string;
|
|
35
|
+
}
|
|
36
|
+
export declare const Locale: import("@aethervtt/shard-core").ResourceDef<LocaleValue>;
|
|
37
|
+
/** The locales tried for `current`, in order: `pt-BR` → `pt` → `en`. */
|
|
38
|
+
export declare function localeChain(current: string, fallback: string): string[];
|
|
39
|
+
interface Merged {
|
|
40
|
+
/** Key → entry, over every loaded table of the locale. */
|
|
41
|
+
strings: Map<string, StringEntry>;
|
|
42
|
+
/** Key → the table it came from, for validation messages. */
|
|
43
|
+
source: Map<string, string>;
|
|
44
|
+
}
|
|
45
|
+
/** Localization state for one world: merged tables, formatters, and what failed to resolve. */
|
|
46
|
+
export declare class LocaleStore {
|
|
47
|
+
/** Bumped when a string table loads, changes, or goes away. */
|
|
48
|
+
revision: number;
|
|
49
|
+
/** The chain tried for the current locale. */
|
|
50
|
+
chain: string[];
|
|
51
|
+
/** Bumped when the chain changes (the locale was switched). */
|
|
52
|
+
chainRevision: number;
|
|
53
|
+
private chainFor;
|
|
54
|
+
private merged;
|
|
55
|
+
private readonly plurals;
|
|
56
|
+
private readonly numbers;
|
|
57
|
+
/** Keys requested at runtime that no locale in the chain had, by locale. */
|
|
58
|
+
readonly missing: Map<string, Set<string>>;
|
|
59
|
+
/** Components whose `key` and `params` fields localize (UiText, Text, ScreenText). */
|
|
60
|
+
readonly targets: {
|
|
61
|
+
def: ComponentDef;
|
|
62
|
+
query: Query | undefined;
|
|
63
|
+
}[];
|
|
64
|
+
/** The resolved string's locale after `resolve` ('' if the key was missing). */
|
|
65
|
+
resolvedLocale: string;
|
|
66
|
+
/** Recomputes the chain if the locale changed. True if it did. */
|
|
67
|
+
sync(locale: LocaleValue): boolean;
|
|
68
|
+
/** Every loaded table's strings, merged per locale (rebuilt after a table changes). */
|
|
69
|
+
tables(world: World): Map<string, Merged>;
|
|
70
|
+
invalidate(): void;
|
|
71
|
+
/**
|
|
72
|
+
* The string for `key` in the first locale of the chain that has it, formatted with `params`.
|
|
73
|
+
* Undefined if none has it (the miss is recorded and logged once).
|
|
74
|
+
*/
|
|
75
|
+
resolve(world: World, key: string, params: unknown): string | undefined;
|
|
76
|
+
/** Formats one entry: picks the plural form, then fills `{name}` placeholders. */
|
|
77
|
+
format(entry: StringEntry, locale: string, params: unknown): string;
|
|
78
|
+
pluralRules(locale: string): Intl.PluralRules;
|
|
79
|
+
numberFormat(locale: string): Intl.NumberFormat;
|
|
80
|
+
}
|
|
81
|
+
export declare const LocaleState: import("@aethervtt/shard-core").ResourceDef<LocaleStore>;
|
|
82
|
+
/**
|
|
83
|
+
* The string for `key` in the current locale: `tr(world, 'hud.fuel', { amount: 42 })`. Falls back
|
|
84
|
+
* along `pt-BR` → `pt` → `en`; plural entries pick their form from `n` (or `count`) with
|
|
85
|
+
* `Intl.PluralRules`, and numbers format with `Intl.NumberFormat`. A missing key returns the key
|
|
86
|
+
* itself (and logs `locale/missing-key` once).
|
|
87
|
+
*/
|
|
88
|
+
export declare function tr(world: World, key: string, params?: Record<string, unknown>): string;
|
|
89
|
+
/** Switches the locale; keyed text updates on the next frame. */
|
|
90
|
+
export declare function setLocale(world: World, locale: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Makes a component's `key` and `params` fields localize: its entities get `text/Localized` with
|
|
93
|
+
* the resolved string. Text, ScreenText, and UiText are registered by their plugins.
|
|
94
|
+
*/
|
|
95
|
+
export declare function localizeComponent(world: World, def: ComponentDef): void;
|
|
96
|
+
/** Resolves localized keys into `text/Localized`: only rows whose text changed, unless the locale or a table did. */
|
|
97
|
+
export declare const localizeText: import("@aethervtt/shard-core").SystemDef<{
|
|
98
|
+
revision: number;
|
|
99
|
+
chain: number;
|
|
100
|
+
}>;
|
|
101
|
+
/** Components that carry localization keys, by name (for scanning files without the classes). */
|
|
102
|
+
export declare const KEYED_COMPONENTS: readonly ['ui/UiText', 'text/Text', 'text/ScreenText'];
|
|
103
|
+
/** Keys used in a scene or prefab file: every keyed component's `key`, with its JSON pointer. */
|
|
104
|
+
export declare function localizationKeysIn(json: unknown): {
|
|
105
|
+
key: string;
|
|
106
|
+
path: string;
|
|
107
|
+
}[];
|
|
108
|
+
export interface LocalizationReport {
|
|
109
|
+
/** Locales with at least one table. */
|
|
110
|
+
locales: string[];
|
|
111
|
+
/** Every key some table defines. */
|
|
112
|
+
keys: Set<string>;
|
|
113
|
+
/** Missing keys and placeholder mismatches, each with the table it concerns. */
|
|
114
|
+
errors: {
|
|
115
|
+
source: string;
|
|
116
|
+
error: ShardError;
|
|
117
|
+
}[];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Checks the project's string tables against each other: a key one locale defines and another
|
|
121
|
+
* lacks (`locale/missing-key`), and a key whose `{placeholders}` differ between locales
|
|
122
|
+
* (`locale/param-mismatch`). Loads every table in the catalog.
|
|
123
|
+
*/
|
|
124
|
+
export declare function validateLocalization(world: World): Promise<LocalizationReport>;
|
|
125
|
+
export declare const localeMethods: AppMethod[];
|
|
126
|
+
/**
|
|
127
|
+
* Localization for an app (idempotent): the Locale resource, string tables, the resolving system,
|
|
128
|
+
* and the locale protocol methods. The text and UI plugins install it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function installLocalization(app: App): void;
|
|
131
|
+
/** Requests every string table in the catalog (small files: all locales stay loaded). */
|
|
132
|
+
export declare function loadStringTables(world: World): Promise<void>;
|
|
133
|
+
export {};
|