Skip to main content

Classes

NameDescription
LocaleUtilsUtility class for loading locale files

Typedefs

NameDescription
LocaleManifestLocale settings and known locale file paths
LocalePathPartPartial URL representing a directory containing locale .json files or a URL template with a :locale path param to a .json file.
LocalePathThunkCallback which receives a context object for resolving a LocalePathPath
LocalePathPartOrThunkA localePathPart string or callback which returns one
LocalePathURL path to a locale .json file
LangLanguage code only
LocaleLanguage code with region
LocalesStateState of loaded locale files
LocalesPropsProps for a Next.js page containing locale and initial state
LocaleStatusFetch status of a locale file

LocaleUtils

Utility class for loading locale files

Kind: global class

new LocaleUtils(config)

ParamTypeDescription
configObjectConfiguration
config.manifestLocaleManifestLocale file manifest
[config.basePath]stringLocale file base path. Defaults to manifest.basePath

localeUtils.getFallbackLocale(locale)

Fallback to the lang part of a locale or to defaultLocale. Strategy is: <locale> <locale lang (if doesn't match default lang)> <default locale (if a locale)> <default lang> null

Here's an example using da-DK/da with en-US as defaultLocale da-DK ==> da ==> en-US ==> en ==> null

Kind: instance method of LocaleUtils
Returns: LocaleLangnull - language - fallback language to use.

ParamTypeDescription
localeLocaleCurrent locale

localeUtils.formatLocalePath(localePathPart, locale)

Format a localePath with provided locale. Ensures path starts with slash and ends with .json file.

Kind: instance method of LocaleUtils
Returns: LocalePath - localePath

ParamTypeDescription
localePathPartLocalePathPartPath containing locale files
localeLocaleLocale

localeUtils.resolveLocalePathPart(localePathPart, [context])

Get a localePathPart from provided string or thunk callback results

Kind: instance method of LocaleUtils
Returns: LocalePath - localePath

ParamTypeDescription
localePathPartLocalePathPartOrThunkPath containing locale files
[context]objectContext

localeUtils.getLocalePath(localePathPart, locale, [context])

Get a formatted localePath considering language mappings and fallbacks

Kind: instance method of LocaleUtils
Returns: LocalePath - localePath

ParamTypeDescription
localePathPartLocalePathPartOrThunkPath containing locale files
localeLocaleLocale
[context]objectContext

localeUtils.pathToUrl(localePath)

Add base path from window.gasket.intl or manifest if set to the locale path

Kind: instance method of LocaleUtils
Returns: string - url

ParamTypeDescription
localePathLocalePathURL path to a locale file

localeUtils.serverLoadData(localePathPart, locale, localesDir)

Load locale file(s) and return localesProps. Throws error if attempted to use in browser.

Kind: instance method of LocaleUtils
Returns: LocalesProps - localesProps

ParamTypeDescription
localePathPartLocalePathPart | Array.<LocalePathPart>Path(s) containing locale files
localeLocaleLocale to load
localesDirstringDisk path to locale files dir

LocaleStatus

Enum for local status values

Kind: global enum
Properties

NameTypeDefault
LOADINGLocaleStatusloading
LOADEDLocaleStatusloaded
ERRORLocaleStatuserror

LocaleStatus.LOADING

Kind: static property of LocaleStatus
Default: loading

LocaleStatus.LOADED

Kind: static property of LocaleStatus
Default: loaded

LocaleStatus.ERROR

Kind: static property of LocaleStatus
Default: error

LocaleManifest

Locale settings and known locale file paths

Kind: global typedef
Properties

NameTypeDescription
[basePath]stringBase URL where locale files are served
localesPathLocalePathPartPath to endpoint with JSON files
defaultLocaleLocaleLocale to fallback to when loading files
[localesMap]ObjectMapping of locales to share files
pathsObjectAvailable locale files to content hashes

LocalePathPart

Partial URL representing a directory containing locale .json files or a URL template with a :locale path param to a .json file.

Kind: global typedef
Example

"/locales"

Example

// as a template
"/locales/:locale/component.json"

Example

// other param formats
"/locales/$locale/component.json"
"/locales/{locale}/component.json"

LocalePathThunk

Callback which receives a context object for resolving a LocalePathPath

Kind: global typedef
Returns: string - localePathPart

ParamType
contextobject

LocalePathPartOrThunk

A localePathPart string or callback which returns one

Kind: global typedef

LocalePath

URL path to a locale .json file

Kind: global typedef
Example

"/locales/en-US.json"

Example

// from a template
"/locales/en-US/component.json"

Lang

Language code only

Kind: global typedef
Example

"en"

Locale

Language code with region

Kind: global typedef
Example

"en-US"

LocalesState

State of loaded locale files

Kind: global typedef
Properties

NameType
messagesObject
statusObject

LocalesProps

Props for a Next.js page containing locale and initial state

Kind: global typedef
Properties

NameType
localeLocale

LocaleStatus

Fetch status of a locale file

Kind: global typedef
Read only: true

LocaleStatus.LOADING

Kind: static property of LocaleStatus
Default: loading

LocaleStatus.LOADED

Kind: static property of LocaleStatus
Default: loaded

LocaleStatus.ERROR

Kind: static property of LocaleStatus
Default: error