Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Lokales

Hierarchy

  • Lokales

Index

Constructors

constructor

Properties

Private _canExit

_canExit: boolean = false

cache

options

path

path: string

queue

queue: any[] = []

Accessors

t

  • get t(): __

tn

  • get tn(): __n

tnx

tx

  • get tx(): __x

Methods

__

  • __(val: TemplateStringsArray, ...args: any[]): string
  • __(val: string, ...args: any[]): string
  • Localize non plurals template strings.

    Parameters

    • val: TemplateStringsArray

      the value to localize.

    • Rest ...args: any[]

      format arguments.

    Returns string

  • Localize non plural string.

    Parameters

    • val: string

      the value to localize.

    • Rest ...args: any[]

      format arguments.

    Returns string

__n

  • __n(singular: string, plural: string, count?: number, ...args: any[]): string
  • Localize plurals.

    Parameters

    • singular: string

      the singular localized value.

    • plural: string

      the pluralized valued.

    • Optional count: number

      the count for the plural value.

    • Rest ...args: any[]

      argument formatters.

    Returns string

__nx

  • __nx(singular: string, plural: string, count?: number, ...args: any[]): ILokalesResult
  • Localize plurals unformated as object.

    Parameters

    • singular: string

      the singular localized value.

    • plural: string

      the pluralized valued.

    • Optional count: number

      the count for the plural value.

    • Rest ...args: any[]

      argument formatters.

    Returns ILokalesResult

__x

  • __x(val: string | TemplateStringsArray, ...args: any[]): ILokalesResult
  • Localize non plural string unformated as object.

    Parameters

    • val: string | TemplateStringsArray

      the value to localize.

    • Rest ...args: any[]

      format arguments.

    Returns ILokalesResult

Private _onQueueEmpty

  • _onQueueEmpty(): void

Private error

  • error(err: string | Error): void
  • Handles module errors.

    Parameters

    • err: string | Error

      the error to be handled.

    Returns void

Private extend

  • extend(dest: any, ...args: any[]): any
  • Minimalistc extend just suits purpose here.

    Parameters

    • dest: any

      the destination object.

    • Rest ...args: any[]

    Returns any

flush

  • flush(): void

getOption

  • getOption(key: string): any
  • Get an option value by key.

    Parameters

    • key: string

      the option key to get.

    Returns any

Private isPlainObject

  • isPlainObject(val: any): boolean
  • Is Plain Object checks if is plain object.

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

Private isValue

  • isValue(val: any): boolean
  • Is Value ensures the provided argument is not undefined, NaN, Infinity etc.

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

keyExists

  • keyExists(key: string, locale?: string, directory?: string): any
  • Key Exists inspects cached checking if key already exists.

    Parameters

    • key: string

      the key to check if exists.

    • Optional locale: string

      the locale to inspect for key.

    • Optional directory: string

      optional directory.

    Returns any

Protected localize

  • localize(singular: string, plural: string, count: number, ...args: any[]): ILokalesResult
  • Localize common method for localizing strings.

    Parameters

    • singular: string

      singular string value.

    • plural: string

      plural string value or count.

    • count: number

      numeric count for pluralization.

    • Rest ...args: any[]

      format args.

    Returns ILokalesResult

Private onExit

  • onExit(type: any, err: any): void
  • Exit handler ensures graceful exit writing any in queue.

    Parameters

    • type: any
    • err: any

    Returns void

onQueueEmpty

  • onQueueEmpty(fn: Function): void
  • A callback function before exit and after queue has been emptied.

    Parameters

    • fn: Function

      a callback function on queue empty and ready to exit.

    Returns void

Private processQueue

  • processQueue(type?: string, err?: any): void
  • Process queued jobs saving to file.

    Parameters

    • Optional type: string
    • Optional err: any

    Returns void

Private readLocale

  • readLocale(locale?: string, directory?: string, graceful?: boolean): any
  • Reads the locale file.

    Parameters

    • Optional locale: string

      the active locale.

    • Optional directory: string

      the directory for locales.

    • Optional graceful: boolean

      mutes errors gracefully logs message.

    Returns any

Private resolveFile

  • resolveFile(locale: string, directory?: string, fallback?: string): string
  • Resolve Locale resolves the locale or fallback path.

    Parameters

    • locale: string

      the locale to be resovled.

    • Optional directory: string

      the directory where locales are stored.

    • Optional fallback: string

    Returns string

Private resolvePath

  • resolvePath(locale?: string, directory?: string): string
  • Resolve the path for a locale file.

    Parameters

    • Optional locale: string

      the locale to use for resolving path.

    • Optional directory: string

      an optional directory for resolving locale file.

    Returns string

setOption

sync

  • sync(from?: string): void
  • Sync ensures secondary locales contain same keys of primary from.

    Parameters

    • Default value from: string = "en"

      the locale to sync from default "en".

    Returns void

Private templateLiteral

  • templateLiteral(strings: string[], values: any[]): string
  • templateLiteral(strings: string[], values: any[], noFormat: boolean): ILokalesResult
  • Template Literal allows for localizing __some localized string ${value};

    Parameters

    • strings: string[]

      array of template literal strings.

    • values: any[]

      template literal args.

    Returns string

  • Template Literal allows for localizing __some localized string ${value};

    Parameters

    • strings: string[]

      array of template literal strings.

    • values: any[]

      template literal args.

    • noFormat: boolean

    Returns ILokalesResult

Private writeFile

  • writeFile(path: string, data: string, updated?: IMap<any> | Function, fn?: any): void
  • Parameters

    • path: string
    • data: string
    • Optional updated: IMap<any> | Function
    • Optional fn: any

    Returns void

Private writeQueue

Generated using TypeDoc