@gasket/plugin-intl
This primary responsibility of this plugin is to build the intl manager script.
Installation
npm i @gasket/plugin-intl
Modify plugins
section of your gasket.js
:
// gasket.js
import { makeGasket } from '@gasket/core';
+ import pluginIntl from '@gasket/plugin-intl';
export default makeGasket({
plugins: [
+ pluginIntl
],
intl: {
locales: ['en-US', 'fr-FR']
}
})
Configuration
To be set under intl
in the gasket.js
. No configuration is
required. However, these options exist to customize an app's setup.
Options
locales
- (string[]) Ordered list of accepted locales. If set, the preferred locale will be resolved based on the requestaccept-language
header.defaultLocale
- (string) Locale to fallback to when loading files. Defaults to the firstlocales
entry if not set.localesMap
- (object) Mapping of locales to share files. See Locales Map section.localesDir
- (string) Path to on-disk directory where locale files exists (default:./locales
)defaultLocaleFilePath
- (string) Lookup path for locale files (default:locales
). See [Locales Path] section.managerFilename
- (string) Change the name of the manager file (default:intl.js
)modules
- (boolean|object|string[]) Enable locale files collation from node modules. Disabled by default, enable by setting to an object with options below, or set totrue
to use the default options. See Module Locales section.localesDir
- (string) Lookup dir for module files (default:locales
)excludes
- (string[]) List of modules to ignore
nextRouting
- (boolean) Enable Next.js Routing when used with @gasket/plugin-nextjs. (default: true)
Example config
// gasket.js
export default makeGasket({
intl: {
defaultLocale: 'fr-FR',
locales: ['fr-FR', 'en-US', 'zh-TW', 'zh-CN', 'zh-HK', 'zh-SG'],
localesMap: {
'zh-HK': 'zh-TW',
'zh-SG': 'zh-CN'
}
}
});
Usage
The plugin will generate an intl.js
file that can be used to manage locale
files for an app.
For details on how the intl manager can be used, see the
@gasket/intl package.
Locale File Path
A localeFilePath
represents be the target where static JSON files exist.
An app or component can use this path to resolve the correct file to
load for a given locale.
For example, let's say we are serving the following locale files:
locales
├── en.json