Unplugin that provides comprehensive Vue I18n integration capabilities for various bundlers including Vite, Webpack, and Nuxt
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Vue I18n build selection, tree-shaking, and performance optimizations including runtime-only builds and message compiler optimization.
Automatic selection of appropriate Vue I18n builds based on environment and configuration.
/**
* Vue I18n build selection strategy
*/
interface BuildSelection {
/**
* Development builds include full message compiler
* Production builds use runtime-only for smaller size
*/
development: 'vue-i18n.esm-bundler.js';
production: 'vue-i18n.runtime.esm-bundler.js';
/**
* Alternative module support
*/
petite: {
development: 'petite-vue-i18n.esm-bundler.js';
production: 'petite-vue-i18n.runtime.esm-bundler.js';
};
}Configure runtime-only builds for production optimization.
/**
* Runtime-only build configuration
*/
interface RuntimeOnlyOptions {
/**
* Use Vue I18n runtime-only build in production
* Excludes message compiler from final bundle
* @default true
*/
runtimeOnly?: boolean;
}Configuration Example:
VueI18nPlugin({
runtimeOnly: true // Automatic in production, full build in development
});
// Results in bundler alias configuration:
// Production: vue-i18n → vue-i18n.runtime.esm-bundler.js
// Development: vue-i18n → vue-i18n.esm-bundler.jsTree-shake legacy Options API for smaller bundles.
/**
* Composition API optimization
*/
interface CompositionAPIOptions {
/**
* Tree-shake legacy Options API, use Composition API only
* Removes $t, $tc, $te methods from Vue instances
* @default true
*/
compositionOnly?: boolean;
}Impact Example:
// With compositionOnly: true (default)
// ✅ Available: useI18n(), useScope(), etc.
// ❌ Removed: this.$t, this.$tc, this.$te, etc.
// With compositionOnly: false
// ✅ Available: Both Composition and Options API
// ⚠️ Larger bundle sizeControl which Vue I18n features are included in the bundle.
/**
* Full install feature control
*/
interface FullInstallOptions {
/**
* Install full Vue I18n feature set including built-in components
* When false, excludes i18n-t, i18n-n, i18n-d components and v-t directive
* @default true
*/
fullInstall?: boolean;
}Feature Impact:
// With fullInstall: true (default)
// ✅ Available: <i18n-t>, <i18n-n>, <i18n-d> components
// ✅ Available: v-t directive
// ✅ Available: All utility functions
// With fullInstall: false
// ❌ Components and directive tree-shaken
// ✅ Available: Core i18n functions only
// ⚠️ Smaller bundle sizeRemove message compiler from production bundles.
/**
* Message compiler optimization
*/
interface MessageCompilerOptions {
/**
* Tree-shake message compiler from bundle
* Requires pre-compiled messages (no runtime compilation)
* @default false
*/
dropMessageCompiler?: boolean;
}Usage Requirements:
VueI18nPlugin({
dropMessageCompiler: true,
// Must pre-compile all messages
include: ['./locales/**']
});
// ⚠️ Warning: All messages must be pre-compiled
// ❌ Runtime message compilation will fail
// ✅ Significant bundle size reductionServer-side rendering optimizations.
/**
* SSR build configuration
*/
interface SSROptions {
/**
* Enable SSR-specific Vue I18n bundle
* Includes server-side optimizations
* @default false
*/
ssr?: boolean;
}SSR Configuration:
// For SSR applications
VueI18nPlugin({
ssr: true,
optimizeTranslationDirective: true // Required for v-t directive in SSR
});Optimize v-t directive for better performance.
/**
* Translation directive optimization
*/
interface DirectiveOptimizationOptions {
/**
* Optimize v-t directive transformation
* Converts v-t to function calls at compile time
* Required for SSR applications using v-t
* @default false
*/
optimizeTranslationDirective?: boolean | string | string[];
}Directive Optimization Examples:
// Basic optimization
VueI18nPlugin({
optimizeTranslationDirective: true
});
// Custom translation function signatures
VueI18nPlugin({
optimizeTranslationDirective: ['$t', 'translate', 'getMessage']
});<!-- Before optimization -->
<p v-t="'message.key'"></p>
<span v-t="{ path: 'user.name', args: { name: 'John' } }"></span>
<!-- After optimization (compile-time transformation) -->
<p>{{ $t('message.key') }}</p>
<span>{{ $t('user.name', { name: 'John' }) }}</span>Choose between Vue I18n variants for different use cases.
/**
* Module type selection
*/
interface ModuleTypeOptions {
/**
* Target Vue I18n module variant
* @default 'vue-i18n'
*/
module?: VueI18nModule;
}
type VueI18nModule = 'vue-i18n' | 'petite-vue-i18n';Module Comparison:
// vue-i18n (default) - Full-featured
VueI18nPlugin({
module: 'vue-i18n'
// ✅ All features available
// ✅ Complete API surface
// ⚠️ Larger bundle size
});
// petite-vue-i18n - Lightweight
VueI18nPlugin({
module: 'petite-vue-i18n'
// ✅ Core i18n functionality
// ❌ Reduced feature set
// ✅ Smaller bundle size
});Optimize non-string value handling.
/**
* String formatting optimization
*/
interface StringFormattingOptions {
/**
* Force stringify numbers, booleans, and null values
* Converts them to message functions returning strings
* @default false
*/
forceStringify?: boolean;
}Stringify Example:
// Original locale data
{
"count": 42,
"enabled": true,
"value": null
}// With forceStringify: false (default)
const messages = {
count: 42, // number
enabled: true, // boolean
value: null // null
};
// With forceStringify: true
const messages = {
count: () => "42", // function returning string
enabled: () => "true", // function returning string
value: () => "null" // function returning string
};/**
* Typical bundle size impact of optimizations
*/
interface BundleSizeImpact {
baseline: '~100KB'; // Full Vue I18n with all features
runtimeOnly: '~75KB'; // -25% (no message compiler)
compositionOnly: '~85KB'; // -15% (no Options API)
fullInstall_false: '~80KB'; // -20% (no built-in components)
dropMessageCompiler: '~60KB'; // -40% (requires pre-compilation)
petiteVueI18n: '~40KB'; // -60% (lightweight variant)
// Combined optimizations
aggressive: '~30KB'; // All optimizations enabled
}/**
* Runtime performance optimizations
*/
interface PerformanceOptimizations {
preCompiledMessages: {
impact: 'Significant';
description: 'Messages compiled to functions at build time';
benefit: 'No runtime parsing or compilation overhead';
};
treeShaking: {
impact: 'Moderate';
description: 'Unused APIs removed from bundle';
benefit: 'Faster JavaScript parsing and execution';
};
directiveOptimization: {
impact: 'Moderate';
description: 'v-t directive compiled to function calls';
benefit: 'Reduced runtime directive processing';
};
}// Maximum optimization for production
VueI18nPlugin({
// Build optimizations
runtimeOnly: true,
compositionOnly: true,
fullInstall: false,
dropMessageCompiler: true,
// Performance optimizations
forceStringify: true,
optimizeTranslationDirective: true,
// Resource optimization
include: ['./locales/**'],
onlyLocales: ['en', 'fr', 'de'],
// Security
strictMessage: true,
escapeHtml: true
});// Development configuration with debugging support
VueI18nPlugin({
// Keep full builds for development
runtimeOnly: false,
compositionOnly: false,
fullInstall: true,
dropMessageCompiler: false,
// Flexible during development
strictMessage: false,
allowDynamic: true,
// Resource processing
include: ['./locales/**', './src/**/*.vue'],
defaultSFCLang: 'yaml' // More readable in development
});// Server-side rendering optimization
VueI18nPlugin({
// SSR requirements
ssr: true,
optimizeTranslationDirective: true, // Required for v-t in SSR
// Production optimizations
runtimeOnly: true,
compositionOnly: true,
dropMessageCompiler: true,
// Resource handling
include: ['./locales/**'],
globalSFCScope: false // Better for SSR hydration
});// Optimized for micro-frontend architecture
VueI18nPlugin({
// Minimal footprint
module: 'petite-vue-i18n',
fullInstall: false,
compositionOnly: true,
dropMessageCompiler: true,
// Shared resources only
onlyLocales: ['en'],
include: ['./shared-locales/**'],
// No global scope to avoid conflicts
globalSFCScope: false
});