Show:

Q.Text Class

Module for loading text from files. Used for translations, A/B testing and more.

Constructor

Item Index

Methods

Methods

get

(
  • name
  • callback
  • [options]
)
Boolean | Q.Request static

Get the text from a specific text source or sources.

Parameters:

  • name String | Array

    The name of the text source. Can be an array, in which case the text sources are merged in the order they are named there.

  • callback Function

    Receives (err, content), may be called sync or async, where content is an Object formed by merging all the named text sources.

  • [options] Object optional

    Options to use for Q.request . May also include:

    • [ignoreCache=false] Boolean optional

      If true, reloads the text source even if it's been already cached.

    • [merge=false] Boolean optional

      For Q.Text.set if content is loaded

    • [language=null] String optional

      Override language

    • [locale=null] String optional

      Override locale

Returns:

Boolean | Q.Request:

Returns true if content was already loaded, otherwise calls the result of Q.request

set

(
  • name
  • content
  • [merges=false]
)
static

Sets the text for a specific text source.

Parameters:

  • name String

    The name of the text source

  • content Object

    The content, a hierarchical object whose leaves are the actual text translated into the current language in Q.Text.language

  • [merges=false] Boolean optional

    If true, merges on top instead of replacing

setLanguage

(
  • language
  • locale
)
static

Sets the language and locale to use in Q.Text.get calls. When Q is initialized, it is set by default from Q.first(Q.info.languages)

Parameters:

  • language String

    Something like "en"

  • locale String

    Something like "US", but can also be blank if unknown