Class: Strings

Strings


new Strings( [filename] [, dir] [, defaultLocale])

Strings.
Parameters:
Name Type Argument Default Description
filename string <optional>
'global' Filename to read strings from each locale. Excluding path and extension.
dir string <optional>
'../../strings/' Path to find folder of available locales, relative to this file.
defaultLocale string <optional>
'en_US' Default and fallback locale to use when unspecified or no string in given locale is found.
Source:

Classes

Locale

Members


<static> localRegExp

Regular Expression to match a valid locale. Attempts to conform to ISO/IEC 15897. Does not accept modifier.
Source:

<private, constant> _stringsDefault :string

Default and fallback locale.
Type:
  • string
Default Value:
  • 'en_US'
Source:

<private, constant> _stringsDir :string

Path to directory storing locale information.
Type:
  • string
Default Value:
  • '../../strings/'
Source:

<private, constant> _stringsFilename :string

Filename in locale directory to read strings from.
Type:
  • string
Default Value:
  • '/global.js'
Source:

defaultLocale :Strings~Locale

Reference to default locale. This is used when a string key is unable to be found in a locale, or the locale doesn't exist.
Type:
Source:

Methods


<static> parseLocale(locale)

Parse the given string as a locale.
Parameters:
Name Type Description
locale string The locale to parse.
Source:
Returns:
Matched groups or null if not a valid locale.
Type
Object

get(key [, locale] [, rep])

Get and format a specific string.
Parameters:
Name Type Argument Description
key string String key to find.
locale string <optional>
Lookup the string in a specific locale.
rep string <optional>
<repeatable>
Data to replace placeholders in the string.
Source:
Returns:
Matched and replaced string, or null if unable to find.
Type
string

getGroup(locale)

Get the locale group of the given locale.
Parameters:
Name Type Description
locale string The locale to fetch.
Source:
Returns:
The locale group, or null if couldn't be found.
Type
Locale

purge()

Purge all strings from memory to force them to be reloaded. Asynchronous. Does not complete immediately.
Source:

reply(common, msg, titleKey, bodyKey [, rep])

Reply to msg with locale strings.
Parameters:
Name Type Argument Description
common Common Reference to Common for reply helper.
msg external:Discord~Message Message to reply to.
titleKey string <nullable>
String key for the title, or null for default.
bodyKey string String key for the body message.
rep string <optional>
<repeatable>
Placeholder replacements for the body only.
Source:
Returns:
Message send promise from external:Discord.
Type
Promise.<external:Discord~Message>