@meniga/translations
v6.1.36-alpha.0
Published
A utility library to help use i18next
Downloads
824
Readme
@meniga/translations
This package handles localization using the i18next module
Translations
There are two ways to use localization for translated content:
- import { Translate } from '@meniga/translations'
<Translate name="someNamespace:someKeyName" />
- import { tfx } from '@meniga/translations'
{ tfx('someNamespace:someKeyName') }
Date formats
This package also has a utility method to fetch the predefined date formats that are found in the dateformatting.json localization file.
Example:
import { getDateFormat } from '@meniga/translations'
const _configDateFormat = getDateFormat('dateFormat')
where 'dateFormat' is the name of the translated key in the dateformatting.json file.
Configuration
The i18n configuration options can be found here: https://www.i18next.com/overview/configuration-options
Create a i18n.js config file in your app to configure your i18next setup. Configuration options for i18next should go in the "init" property.
Example config:
module.exports = {
init: {
debug: false,
fallbackLng: 'en',
ns: ['app', 'dateformatting', 'numberFormatting'],
defaultNS: 'app',
fallbackNS: 'app',
appendNamespaceToMissingKey: false,
returnEmptyString: false,
},
useBackend: true,
loadPath: '/public/localization-{{lng}}/{{ns}}.json',
expirationTime: 7*24*60*60*1000,
cacheVersions: {
en: 'v1.0',
is: 'v1.0',
},
cultures: [
{ label: 'English', value: 'en-GB'}
]
}
init is for config options supported by i18next, such as defining the default namespaces and languages to load
useBackends defines whether or not to use a backend (with caching) for translations or to load them in memory. If backend is used, language packs can be added/edited during runtime, and don't require a new build. You can define what the path to the language packs is, and when the cache should be expired.
loadPath defines the location of the files when using backend
expirationTime defines the time in milliseconds when the backend cache should be automatically expired
cacheVersions is an object you can use to specify a version for each culture, in order to control the caching. If a version is bumped the cache will automatically be expired.
cultures a list of supported cultures in Bank42 that will appear in the Change Culture dropdown component