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

PropertyDefaultDescription
defaultLocaleA 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.
localesAn array of LocaleDescriptor objects that represent all the configured locales.
storageAn 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.
broadcastLocaleChangetrueAn 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.
onParseErrorAn 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.

PropertyDescription
fileAn 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.
filesAn 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.
tagA string that represents the BCP 47 language tag of the locale.
additionalImportsAn optional array of UnspecifiedImportSource that represent additional side-effect only imports, such as polyfill data.
resourcesAn 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.
metaAn 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
    1sourceA string that represents the import path of the file.
    2exportNameA string that represents the name of the export to be imported from the file.
  • An object containing from property with import path and name property with module path.
    PropertyDefaultDescription
    fromA string that represents the import path of the file.
    nameA string that represents the name of the export to be imported from the file.
    resolvetrueA 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 optionally resolve property.
    PropertyDefaultDescription
    fromA string that represents the import path of the file.
    resolvetrueA 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.

PropertyDefaultDescription
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.
parserAn 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.

PropertyDefaultDescription
enabledfalseA ParserlessMode value representing the status of the parserless mode.

ParserlessMode

A string or boolean value representing the status of the parserless mode.

ValueBoolean valueMeaning
alwaystrueParserless mode is always enabled, regardless of the mode in which Nuxt is running.
only-prodParserless mode is only enabled when building Nuxt app for production.
neverfalseParserless 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.

PropertyDefaultDescription
enabledtrueA 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:hlA string value representing the query parameter that VIntl would use to configure the language of the site.
baseURLRecommended. 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.
defaultLocaleHasParametertrueA 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).
xDefaultHreflangtrueA 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:
    NameStrategy
    use-message-as-literalUse the raw message contents as a literal.
    use-id-as-literalUse the message ID as a literal.
    use-empty-literalUse empty string as a literal.
    log-and-skipLog the error to console and don't include the message into the transformed file.
    skipSkip 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).