Registry / web-framework / vue-intl

vue-intl

JSON →
library7.2.3jsnpmunverified

Vue Intl is the official FormatJS binding for Vue.js applications, providing comprehensive internationalization (i18n) and localization (l10n) capabilities. Currently at version 7.2.3, it is actively maintained as part of the broader FormatJS monorepo, which sees frequent updates across its packages. The library leverages web standards like the JavaScript `Intl` API, ECMA-402, Unicode CLDR, and ICU Message syntax for robust and accurate formatting of messages, dates, numbers, and more. It offers seamless integration with Vue 3's Composition API via `useIntl()` and also supports injection patterns, distinguishing itself by being part of a well-established, standards-compliant internationalization ecosystem with extensive tooling for message extraction and compilation.

npm install vue-intl
INSTALL
IMPORT
SIG · VUE-INTL
V
vue-intl
web-frameworkjavascriptv7.2.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createIntl
import { createIntl } from 'vue-intl'
const createIntl = require('vue-intl')
Used to initialize the Vue Intl plugin with locale configuration. Vue Intl is primarily designed for ESM.
useIntl
import { useIntl } from 'vue-intl'
A Composition API hook to access the intl formatters and methods within a Vue 3 component. No direct CommonJS equivalent for hooks.
IntlConfig
import type { IntlConfig } from 'vue-intl'
TypeScript type for configuring the Intl plugin. Useful for strict type checking during setup.

Demonstrates how to install `vue-intl`, configure it as a Vue plugin with messages, and use the `useIntl` Composition API hook for message formatting, alongside template-based formatters like `$formatDate` and `$formatMessage`.

import { createApp } from 'vue'; import App from './App.vue'; import { createIntl, useIntl } from 'vue-intl'; // 1. Define your messages for a locale const messages = { en: { greeting: 'Hello, {name}!', current_date: 'Today is {ts, date, ::yyyyMMdd}', photo_count: '{count, plural, one {# photo} other {# photos}} taken.' }, fr: { greeting: 'Bonjour, {name}!', current_date: 'Aujourd'hui, c'est le {ts, date, ::yyyyMMdd}', photo_count: '{count, plural, one {# photo} other {# photos}} pris.' } }; // 2. Create the Vue app instance const app = createApp(App); // 3. Install the vue-intl plugin app.use(createIntl({ locale: 'en', defaultLocale: 'en', messages: messages.en, // Load locale data dynamically in a real app // For production, consider using @formatjs/cli or babel-plugin-formatjs for message compilation })); // 4. Example Vue component using useIntl hook const MyComponent = { template: ` <div> <p>{{ formattedGreeting }}</p> <p>{{ $formatDate(new Date(), { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) }}</p> <p>{{ $formatMessage({ id: 'photo_count', defaultMessage: 'No photos.', description: 'Number of photos' }, { count: photoCount }) }}</p> </div> `, setup() { const intl = useIntl(); const photoCount = 5; // Example dynamic value const formattedGreeting = intl.formatMessage({ id: 'greeting', defaultMessage: 'Hello, world!' }, { name: 'Vue User' }); return { formattedGreeting, photoCount }; }, }; app.component('MyComponent', MyComponent); app.mount('#app');
Debug
Known issues
gotchaVue's template interpolation (`{{ ... }}`) can conflict with ICU MessageFormat's double curly brace syntax (e.g., `{count, plural, one {#}}`). This can lead to parsing errors in Vue Single File Components (SFCs).
fix
Add a space inside the ICU MessageFormat's double curly braces, e.g., change `{{#}}` to `{ {#} }` or `{{ more}}` to `{ { more} }`.
affects: >=1.0.0
gotchaBy default, `vue-intl` only includes locale data for the 'en' locale. For other languages or specific formatting rules (e.g., pluralization, relative time), you must explicitly load the corresponding locale data to avoid incorrect or default formatting.
fix
Dynamically import and register locale data for each language your application supports, for example, `import frLocaleData from 'vue-intl/locale-data/fr';`.
affects: >=1.0.0
gotchaThe underlying FormatJS libraries rely on the browser's native `Intl` API. For older browsers or environments without full `Intl` support, a polyfill (e.g., `@formatjs/intl-pluralrules`, `@formatjs/intl-relativetimeformat`) is required to ensure consistent internationalization behavior.
fix
Conditionally load the necessary `Intl` polyfills based on browser support or include them directly in your build process for wider compatibility.
affects: >=1.0.0
breakingWhile no direct `vue-intl` v6-to-v7 migration guide is provided, the broader FormatJS ecosystem (which `vue-intl` is a part of) transitioned its build outputs to ES6 for CDN bundles and CommonJS files starting from v7 across many packages. This affects projects targeting older environments (e.g., ES5, IE11, older Node.js versions) and may require a transpiler or reconfiguration of build targets.
fix
Ensure your build tooling (e.g., Babel, Webpack, Vite) is configured to transpile ES6 output if targeting older environments. Check FormatJS migration guides for specific packages if upgrading other FormatJS dependencies alongside `vue-intl`.
affects: >=7.0.0
Errors
Common errors & fixes
The message format compilation is not supported in this build.
ICU message strings (e.g., plural rules, select formats) are being used directly in the browser runtime without prior compilation, which is not supported by the default runtime-only build.
fix
Utilize `@formatjs/cli`, `babel-plugin-formatjs`, or `@formatjs/ts-transformer` during your build process to pre-compile messages. This converts ICU strings into optimized JavaScript functions, improving performance and enabling advanced formatting.
Messages are not displaying or falling back to message ID string.
The `id` for a message cannot be found in the provided `messages` object for the current locale, or the locale data is missing/incorrect.
fix
Verify that the message `id` passed to `$formatMessage` or `intl.formatMessage` exists in your registered message dictionaries. Ensure that the correct locale messages are loaded and set for the application.
Upgrade
Version history
7.2.3latest on npm
Audit
Dependencies
vuerequiredPeer dependency for Vue.js 3 integration.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources