Options
All
  • Public
  • Public/Protected
  • All
Menu

Gettext class providing localization methods.

Hierarchy

  • Gettext

Index

Constructors

constructor

  • new Gettext(options?: IOptions): Gettext
  • Parameters

    • Optional options: IOptions

    Returns Gettext

Properties

Private _contextDelimiter

_contextDelimiter: any

Private _defaults

_defaults: any

Private _dictionary

_dictionary: any

Private _domain

_domain: any

Private _locale

_locale: any

Private _pluralForms

_pluralForms: any

Private _pluralFuncs

_pluralFuncs: any

Private _stringsPrefix

_stringsPrefix: any

Private expandLocale

expandLocale: any

Split a locale into parent locales. "es-CO" -> ["es-CO", "es"]

param

The locale string.

returns

An array of locales.

Private getPluralFunc

getPluralFunc: any

Split a locale into parent locales. "es-CO" -> ["es-CO", "es"]

param

Plural form string..

returns

An function to compute plural forms.

Private removeContext

removeContext: any

Remove the context delimiter from string.

param

Translation string.

returns

A translation string without context.

Private setMessages

setMessages: any

Set messages after loading them.

param

The translation domain.

param

The translation locale.

param

List of translation strings.

param

Plural form string.

Notes

Contains juicy parts of https://github.com/Orange-OpenSource/gettext.js/blob/master/lib.gettext.js

Private t

t: any

Proper translation function that handle plurals and directives.

param

List of translation strings.

param

The number for pluralization.

param

Translation options.

param

Any variables to interpolate.

returns

A translation string without context.

Notes

Contains juicy parts of https://github.com/Orange-OpenSource/gettext.js/blob/master/lib.gettext.js

Methods

__

  • __(msgid: string, ...args: any[]): string
  • Shorthand for gettext.

    Parameters

    • msgid: string

      The singular string to translate.

    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

    Notes

    This is not a private method (starts with an underscore) it is just a shorter and standard way to call these methods.

_n

  • _n(msgid: string, msgid_plural: string, n: number, ...args: any[]): string
  • Shorthand for ngettext.

    Parameters

    • msgid: string

      The singular string to translate.

    • msgid_plural: string

      The plural string to translate.

    • n: number

      The number for pluralization.

    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

    Notes

    This is not a private method (starts with an underscore) it is just a shorter and standard way to call these methods.

_np

  • _np(msgctxt: string, msgid: string, msgid_plural: string, n: number, ...args: any[]): string
  • Shorthand for npgettext.

    Parameters

    • msgctxt: string

      The message context.

    • msgid: string

      The singular string to translate.

    • msgid_plural: string

      The plural string to translate.

    • n: number

      The number for pluralization.

    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

    Notes

    This is not a private method (starts with an underscore) it is just a shorter and standard way to call these methods.

_p

  • _p(msgctxt: string, msgid: string, ...args: any[]): string
  • Shorthand for pgettext.

    Parameters

    • msgctxt: string

      The message context.

    • msgid: string

      The singular string to translate.

    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

    Notes

    This is not a private method (starts with an underscore) it is just a shorter and standard way to call these methods.

dcnpgettext

  • dcnpgettext(domain: string, msgctxt: string, msgid: string, msgid_plural: string, n: number, ...args: any[]): string
  • Translate a singular string with extra interpolation values.

    Parameters

    • domain: string

      The translations domain.

    • msgctxt: string

      The message context.

    • msgid: string

      The singular string to translate.

    • msgid_plural: string

      The plural string to translate.

    • n: number

      The number for pluralization.

    • Rest ...args: any[]

      Any additional values to use with interpolation

    Returns string

    A translated string if found, or the original string.

getContextDelimiter

  • getContextDelimiter(): string
  • Get current context delimiter.

    Returns string

    The current delimiter.

getDomain

  • getDomain(): string
  • Get current domain.

    Returns string

    The current domain string.

getLocale

  • getLocale(): string
  • Get current locale.

    Returns string

    The current locale.

getStringsPrefix

  • getStringsPrefix(): string
  • Get current strings prefix.

    Returns string

    The strings prefix.

gettext

  • gettext(msgid: string, ...args: any[]): string
  • Translate a singular string with extra interpolation values.

    Parameters

    • msgid: string

      The singular string to translate.

    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

loadJSON

  • loadJSON(jsonData: IJsonData, domain: string): void
  • Load json translations strings (In Jed 2.x format).

    Parameters

    • jsonData: IJsonData

      The translation strings plus metadata.

    • domain: string

      The translation domain, e.g. "jupyterlab".

    Returns void

ngettext

  • ngettext(msgid: string, msgid_plural: string, n: number, ...args: any[]): string
  • Translate a plural string with extra interpolation values.

    Parameters

    • msgid: string

      The singular string to translate.

    • msgid_plural: string
    • n: number
    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

npgettext

  • npgettext(msgctxt: string, msgid: string, msgid_plural: string, n: number, ...args: any[]): string
  • Translate a contextualized plural string with extra interpolation values.

    Parameters

    • msgctxt: string

      The message context.

    • msgid: string

      The singular string to translate.

    • msgid_plural: string

      The plural string to translate.

    • n: number

      The number for pluralization.

    • Rest ...args: any[]

      Any additional values to use with interpolation

    Returns string

    A translated string if found, or the original string.

pgettext

  • pgettext(msgctxt: string, msgid: string, ...args: any[]): string
  • Translate a contextualized singular string with extra interpolation values.

    Parameters

    • msgctxt: string

      The message context.

    • msgid: string

      The singular string to translate.

    • Rest ...args: any[]

      Any additional values to use with interpolation.

    Returns string

    A translated string if found, or the original string.

    Notes

    This is not a private method (starts with an underscore) it is just a shorter and standard way to call these methods.

setContextDelimiter

  • setContextDelimiter(delimiter: string): void
  • Set current context delimiter.

    Parameters

    • delimiter: string

      The delimiter to set.

    Returns void

setDomain

  • setDomain(domain: string): void
  • Set current domain.

    Parameters

    • domain: string

      The domain to set.

    Returns void

setLocale

  • setLocale(locale: string): void
  • Set current locale.

    Parameters

    • locale: string

      The locale to set.

    Returns void

setStringsPrefix

  • setStringsPrefix(prefix: string): void
  • Set current strings prefix.

    Parameters

    • prefix: string

      The string prefix to set.

    Returns void

Static strfmt

  • strfmt(fmt: string, ...args: any[]): string
  • sprintf equivalent, takes a string and some arguments to make a computed string.

    Parameters

    • fmt: string

      The string to interpolate.

    • Rest ...args: any[]

      The variables to use in interpolation.

      Examples

      strfmt("%1 dogs are in %2", 7, "the kitchen"); => "7 dogs are in the kitchen" strfmt("I like %1, bananas and %1", "apples"); => "I like apples, bananas and apples"

    Returns string

Generated using TypeDoc