Configuration
VIntl for Nuxt provides variety of options to configure the plugin and integration.
Some options will be checked when launching Nuxt in dev or build modes.
ModuleOptions
Represents the VIntl module options.
Properties
Property | Default | Description |
---|---|---|
defaultLocale | A string that represents the BCP 47 code of the locale to use by default. | |
resolveDir | '.' | An optional string that represents a directory where all the imports associated with the locales are being resolved. If it's relative, then it will be resolved against the Nuxt srcDir directory. If this property is not set, modules will be resolved from the Nuxt srcDir . |
locales | An array of LocaleDescriptor objects that represent all the configured locales. | |
storage | An optional string that represents either a built-in storage name (localStorage / cookie ), or a node import specifier that exports a custom storage adapter as the default export. | |
broadcastLocaleChange | true | An optional boolean value that determines whether to use BroadcastChannel (if available) to synchronize the locale changes between the tabs on the same origin. |
hostLanguageParam | 'hl' | Deprecated. An optional name of the query parameter used to override the user language (including automatically detected one). It is used to generate SEO meta tags. Using null will disable them. |
parserless | <...> | An optional ParserlessOptions object or ParserlessMode which configures the parserless mode. |
seo | <...> | An optional SEOOptions object which configures automatic head tags to improve discoverability of other languages by search engines. |
onParseError | An optional ParsingErrorHandlingOption value that defines how to handle errors that occur when transforming message files. If not defined, the errors are not handled and thrown during the building, preventing it from succeeding. |
LocaleDescriptor
Represents a configured locale.
Property | Description |
---|---|
file | An optional MessagesImportSource that represents a source of import for the messages file. If the files option is specified together with this option, this messages file will be imported before any other file defined in files . |
files | An optional array of MessagesImportSource that represent import sources for the message files. The messages in previously imported sources will be overridden by the messages in later imported sources in the order of their appearance in the array. |
tag | A string that represents the BCP 47 language tag of the locale. |
additionalImports | An optional array of UnspecifiedImportSource that represent additional side-effect only imports, such as polyfill data. |
resources | An optional object representing the resources map, where each key is a resource name and values are ImportSource . Unlike additional imports, these imports will be accessible through VIntl instance. This is useful for language-associated documents that would otherwise create a frustrating experience for translators if left as regular strings in the messages file. |
meta | An optional object that represents custom meta for the locale. It can be used to store data like language display name or translations percentage. It has to be JSON serializable. |
ImportSource
Represents an import source for a file. It can be one of the following:
- A string with the a path / Node.js module ID to import the default export from.
- An array (tuple) of an import path or and export name from the module imported from that path.
Index (Name) Description 1
source
A string that represents the import path of the file. 2
exportName
A string that represents the name of the export to be imported from the file. - An object containing
from
property with import path andname
property with module path.Property Default Description from
A string that represents the import path of the file. name
A string that represents the name of the export to be imported from the file. resolve
true
A boolean value indicating whether the import path must be resolved or used as is is.
Here's how some of the example values will be expanded:
// './locales/en-US/document.md'
import localeData$rabc12ef3 from '<resolveDir>/locales/en-US/document.md'
// `'@org/pkg/data/en-US/document.md'`
import localeData$rabc12ef3 from '@org/pkg/data/en-US/document.md'
// `['./locales/en-US/index.js', 'document']`
import { document as localeData$rabc12ef3 } from '../../locales/en-US/index.js'
// `{ from: '@org/pkg/data/messages.res', name: 'enUS' }`
import { enUS as localeData$rabc12ef3 } from '../../node_modules/@org/pkg/dist/data/en-US/messages.res'
// `{ from: '@org/pkg/data/messages.res', name: 'enUS', resolve: false }`
import { enUS as localeData$rabc12ef3 } from '@org/pkg/data/en-US/messages.res'
There's an issue with Vite where dependencies imported by direct path will not be cached and instead imported as separate modules. This can break data imports that rely on importing the module rather than expanding some global property. This is where resolve
property comes in handy: it does not perform resolution and imports the path as is.
Alias imports are currently not supported, but will be in the future.
UnspecifiedImportSource
Represents an import source without any specifiers, also known as side-effect only imports.
It can be one of the following:
- A string with the a path / Node.js module ID to import.
- An object containing
from
property with import path, and optionallyresolve
property.Property Default Description from
A string that represents the import path of the file. resolve
true
A boolean value indicating whether the import path must be resolved or used as is is.
Examples:
// '@org/pkg/polyfill/add-global-data/en'
import '../../node_modules/@org/pkg/dist/polyfill/add-global-data/en.mjs'
// { from: '@org/pkg/polyfill/add-global-data/en', resolve: false }
import '@org/pkg/polyfill/add-global-data/en'
MessagesImportSource
Represents an import source for the messages file. It is similar to the ImportSource
, but can have additional options specifying the format or formatter of the file, as well as parser function. It does not have resolve
option, as resolution is required to properly process message files.
Property | Default | Description |
---|---|---|
format | 'default' | An optional string that represents a FormatJS format name or a function that accepts an unknown value in and returns a record where keys are messages IDs and values are the message contents. |
parser | An optional function which accepts file contents and module ID and parses it (useful, for example, for TOML files). |
ParserlessOptions
Represents options for the parserless mode.
Property | Default | Description |
---|---|---|
enabled | false | A ParserlessMode value representing the status of the parserless mode. |
ParserlessMode
A string or boolean value representing the status of the parserless mode.
Value | Boolean value | Meaning |
---|---|---|
always | true | Parserless mode is always enabled, regardless of the mode in which Nuxt is running. |
only-prod | Parserless mode is only enabled when building Nuxt app for production. | |
never | false | Parserless mode is never enabled, the parser is always present in the runtime. |
SEOOptions
Represents options for the automatic head tags.
By default VIntl will add <link>
tags for every language to make search engines aware of other languages, you can disable this by setting enabled
to false
.
Property | Default | Description |
---|---|---|
enabled | true | A boolean value representing whether VIntl should automatically add <link> tags to <head> of the site. These tags make search engines aware that your site is provided in different languages. |
hostLanguageParameter : | hl | A string value representing the query parameter that VIntl would use to configure the language of the site. |
baseURL | Recommended. An optional string value representing the base URL of the site. If not set, VIntl will try to guess the URL based on inital request URL or the current window.location . | |
defaultLocaleHasParameter | true | A boolean value representing whether the default locale should have a host language parameter. Disabling this may make URLs of visitors cleaner, however it is not correct, because lack of host language instructs VIntl to use user's language (either the one they've used before or browser's one). |
xDefaultHreflang | true | A boolean value representing whether the x-default hreflang is present. |
ParsingErrorHandlingOption
Represents a value for the message pasing error handling option.
It can be one of the following:
- A string containing a name of the strategy for handling the errors. The following strategies are available:
Name Strategy use-message-as-literal
Use the raw message contents as a literal. use-id-as-literal
Use the message ID as a literal. use-empty-literal
Use empty string as a literal. log-and-skip
Log the error to console and don't include the message into the transformed file. skip
Skip including the message into the transformed file. - An function that takes in a context for the error (that includes error itself) and optionally returns a fallback AST (not returning anything skips including the message into the transformed file).