SilkBundle
import { SilkBundle } from 'pixi-silk/i18n';
A loaded .silk bundle (brief sec. 5) with lookups: messages by key, faces by id, slots, tags,
variants by plural category, and number formatting through the baked digit tables. Holds typed
arrays over the fetched buffer and decodes nothing up front.
Constructors#
Constructor#
new SilkBundle(data: ArrayBuffer | BundleData, url?: string): SilkBundle;
Parameters#
| Parameter | Type | Default value |
|---|---|---|
data | ArrayBuffer | BundleData | undefined |
url | string | '' |
Returns#
SilkBundle
Properties#
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
data | readonly | BundleData | The raw tables. | packages/pixi-silk/src/i18n/messages.ts:93 |
url | readonly | string | URL the bundle was loaded from, used to resolve atlas page files. Empty when unknown. | packages/pixi-silk/src/i18n/messages.ts:95 |
Accessors#
dir#
Get Signature#
get dir(): 0 | 1;
Paragraph direction: 0 left to right, 1 right to left.
Returns
0 | 1
faces#
Get Signature#
get faces(): ReadonlyMap<number, BundleFace>;
Faces, by id.
Returns
ReadonlyMap<number, BundleFace>
glyphCount#
Get Signature#
get glyphCount(): number;
Number of atlas glyph records (record 0 is the empty glyph).
Returns
number
id#
Get Signature#
get id(): string;
The app’s code for the locale (the bundle name), such as iq for ar-IQ.
Returns
string
locale#
Get Signature#
get locale(): string;
BCP 47 locale: what plural rules and number formatting use.
Returns
string
Methods#
face()#
face(id: number): BundleFace;
Face by id. Throws when the bundle has no such face.
Parameters#
| Parameter | Type |
|---|---|
id | number |
Returns#
fastPath()#
fastPath(slot: BundleSlot): boolean;
True when number slot updates of the same length can skip layout (tabular digits baked).
Parameters#
| Parameter | Type |
|---|---|
slot | BundleSlot |
Returns#
boolean
formatNumber()#
formatNumber(slot: BundleSlot, value: number): FormattedNumber;
Formats a number for a slot with Intl.NumberFormat in the bundle’s pinned numbering system
(as a percentage for slots declared percent),
then maps every character through the slot’s digit table. A character the table lacks (a
browser whose ICU differs) falls back to Latin digits from the same table, never to a missing
glyph.
Parameters#
| Parameter | Type |
|---|---|
slot | BundleSlot |
value | number |
Returns#
keyOf()#
keyOf(message: number): string;
Key string of a message, when the bundle keeps keys (dev builds), else its hash in hex.
Parameters#
| Parameter | Type |
|---|---|
message | number |
Returns#
string
message()#
message(key: string): number;
Message index of a key, or -1.
Parameters#
| Parameter | Type |
|---|---|
key | string |
Returns#
number
pages()#
pages(): BundlePage[];
Atlas pages the bundle draws from, in the order its glyphs refer to them.
Returns#
pluralCategory()#
pluralCategory(n: number): "zero" | "one" | "two" | "few" | "many" | "other";
Plural category of a number in the bundle’s locale. Uses the platform’s Intl.PluralRules.
Parameters#
| Parameter | Type |
|---|---|
n | number |
Returns#
"zero" | "one" | "two" | "few" | "many" | "other"
selector()#
selector(message: number): number;
Slot id that selects the plural variant of a message, or -1.
Parameters#
| Parameter | Type |
|---|---|
message | number |
Returns#
number
slot()#
slot(id: number): BundleSlot;
Slot record.
Parameters#
| Parameter | Type |
|---|---|
id | number |
Returns#
tag()#
tag(id: number): string;
Tag name of a tag id.
Parameters#
| Parameter | Type |
|---|---|
id | number |
Returns#
string
variant()#
variant(message: number, category?: "zero" | "one" | "two" | "few" | "many" | "other"): number;
Variant index for a plural category: the matching variant, else other, else the first one.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
message | number | undefined |
category | "zero" | "one" | "two" | "few" | "many" | "other" | 'other' |
Returns#
number
variantText()#
variantText(variant: number): string;
Text of a variant, holes as U+FFFC. Empty when the bundle has none.
Parameters#
| Parameter | Type |
|---|---|
variant | number |
Returns#
string