Skip to content

Latest commit

 

History

History
488 lines (251 loc) · 9.48 KB

File metadata and controls

488 lines (251 loc) · 9.48 KB

@hydroperx/pi


@hydroperx/pi / / PI

Class: PI

Defined in: src/index.ts:10

PI stands for product internationalization. PI manages Project Fluent translation lists (FTL) and translates messages.

Extends

  • EventTarget

Constructors

Constructor

new PI(params): PI

Defined in: src/index.ts:47

Parameters

params

PIParams

Returns

PI

Overrides

EventTarget.constructor

Accessors

currentLocale

Get Signature

get currentLocale(): Locale | null

Defined in: src/index.ts:138

Returns the currently loaded locale or null if none.

Returns

Locale | null


fallbacks

Get Signature

get fallbacks(): Locale[]

Defined in: src/index.ts:157

Returns the currently loaded fallbacks.

Returns

Locale[]


localeAndFallbacks

Get Signature

get localeAndFallbacks(): Locale[]

Defined in: src/index.ts:145

Returns the currently loaded locale followed by its fallbacks or empty if no locale is loaded.

Returns

Locale[]


locales

Get Signature

get locales(): Set<Locale>

Defined in: src/index.ts:118

Returns a set of supported locales, reflecting the ones that were specified when constructing the PI object.

Returns

Set<Locale>


status

Get Signature

get status(): PIStatus

Defined in: src/index.ts:170

Returns the status of the PI instance (e.g., "ok", "loading" or "error").

Returns

PIStatus

Methods

addBundleInitializer()

addBundleInitializer(fn): void

Defined in: src/index.ts:110

Adds a bundle initializer. This allows defining custom functions and more.

Parameters

fn

BundleInitializer

Returns

void


addEventListener()

addEventListener(type, callback, options?): void

Defined in: node_modules/typescript/lib/lib.dom.d.ts:8303

Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

MDN Reference

Parameters

type

string

callback

EventListenerOrEventListenerObject | null

options?

boolean | AddEventListenerOptions

Returns

void

Inherited from

EventTarget.addEventListener


clone()

clone(): PI

Defined in: src/index.ts:388

Clones the PI object, but returning an object that is in sync with the original PI object.

Returns

PI


dispatchEvent()

dispatchEvent(event): boolean

Defined in: node_modules/typescript/lib/lib.dom.d.ts:8309

Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

MDN Reference

Parameters

event

Event

Returns

boolean

Inherited from

EventTarget.dispatchEvent


get()

get(id, args, errors): string | null

Defined in: src/index.ts:272

Retrieves message and formats it. Returns null if undefined.

Look at @fluent/bundle for FluentVariable.

Parameters

id

string

args

Record<string, FluentVariable> | undefined

errors

Error[] | null

Returns

string | null


has()

has(id): boolean

Defined in: src/index.ts:325

Determines if a message is defined.

Parameters

id

string

Returns

boolean


load()

load(newLocale): Promise<boolean>

Defined in: src/index.ts:186

Attempts to load a locale and its fallbacks. If the locale argument is specified, it is loaded. Otherwise, if there is a default locale, it is loaded, and if not, the method throws an error.

If any resource fails to load, the returned Promise resolves to false, otherwise true.

Also dispatches either the load or error event, when loading is completed.

Parameters

newLocale

Locale | null

Returns

Promise<boolean>


off()

Call Signature

off<T>(type, listener, params?): void

Defined in: src/index.ts:373

Shortcut for the removeEventListener() method.

Type Parameters
T

T extends keyof PIEventMap

Parameters
type

T

listener

(event) => void

params?

boolean | EventListenerOptions

Returns

void

Call Signature

off(type, listener, params?): void

Defined in: src/index.ts:378

Shortcut for the removeEventListener() method.

Parameters
type

string

listener

Function

params?

boolean | EventListenerOptions

Returns

void


on()

Call Signature

on<T>(type, listener, params?): void

Defined in: src/index.ts:359

Shortcut for the addEventListener() method.

Type Parameters
T

T extends keyof PIEventMap

Parameters
type

T

listener

(event) => void

params?

boolean | AddEventListenerOptions

Returns

void

Call Signature

on(type, listener, params?): void

Defined in: src/index.ts:364

Shortcut for the addEventListener() method.

Parameters
type

string

listener

Function

params?

boolean | AddEventListenerOptions

Returns

void


removeEventListener()

removeEventListener(type, callback, options?): void

Defined in: node_modules/typescript/lib/lib.dom.d.ts:8315

Removes the event listener in target's event listener list with the same type, callback, and options.

MDN Reference

Parameters

type

string

callback

EventListenerOrEventListenerObject | null

options?

boolean | EventListenerOptions

Returns

void

Inherited from

EventTarget.removeEventListener


supportsLocale()

supportsLocale(argument): boolean

Defined in: src/index.ts:131

Returns true if the locale is one of the supported locales that were specified when constructing the PI object, otherwise false.

Parameters

argument

string | Locale

Returns

boolean