@maz-ui/translations
Translations for Maz-UI library
162,002
565
| Install | |
|---|---|
npm install @maz-ui/translations |
|
| Latest Version: | 5.0.0 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | Oct 21, 2026 |
| Links: | GitHub · npm |
Maintainer: louismazel
@maz-ui/translations
Simple and lightweight translation system for Maz-UI components.
Installation
npm install @maz-ui/translations
Features
- 🌍 Simple internationalization for Maz-UI components
- 🔄 Reactive locale switching
- 📝 Variable interpolation in translations
- 🎯 TypeScript support with full type safety
- 🔧 Plugin-based integration with Vue applications
- 📦 Lightweight - minimal bundle size impact
- 🎨 Customizable - override default translations easily
Usage
Basic Configuration
import { MazUiTranslations } from '@maz-ui/translations'
import { createApp } from 'vue'
const app = createApp(App)
app.use(MazUiTranslations, {
locale: 'fr',
translations: {
fr: {
checklist: {
noResultsFound: 'Aucun résultat trouvé',
searchInput: {
placeholder: 'Rechercher',
},
},
},
es: {
checklist: {
noResultsFound: 'No se encontraron resultados',
searchInput: {
placeholder: 'Buscar',
},
},
}
}
})
In Vue Components
<script setup>
import { useTranslations } from '@maz-ui/translations'
const { t, locale, setLocale } = useTranslations()
// Basic usage
const message = t('checklist.noResultsFound')
// With variables
const welcomeMessage = t('checklist.searchInput.placeholder', { name: 'John' })
// Change language
function switchLanguage(lang) {
setLocale(lang)
}
</script>
<template>
<div>
<p>{{ t('checklist.noResultsFound') }}</p>
<p>{{ t('checklist.searchInput.placeholder', { name: 'User' }) }}</p>
<div class="language-switcher">
<button @click="setLocale('en')">
English
</button>
<button @click="setLocale('fr')">
Français
</button>
<button @click="setLocale('es')">
Español
</button>
</div>
<p>Current locale: {{ locale }}</p>
</div>
</template>
Variable Interpolation
The translation system supports variable interpolation using curly braces:
// Configuration
const translations = {
en: {
welcome: 'Hello {name}!',
itemCount: 'You have {count} {count, plural, one {item} other {items}}'
}
}
// Usage
t('welcome', { name: 'John' }) // "Hello John!"
t('itemCount', { count: 1 }) // "You have 1 item"
t('itemCount', { count: 5 }) // "You have 5 items"
Advanced Usage
Manual Instance Creation
import { createMazUiTranslations } from '@maz-ui/translations'
const i18n = createMazUiTranslations({
locale: 'en',
translations: {
en: { /* your translations */ },
fr: { /* your translations */ }
}
})
// Use directly
const message = i18n.t('checklist.noResultsFound')
Custom Translation Keys
// Define your own translation structure
const customTranslations = {
en: {
navigation: {
home: 'Home',
about: 'About',
contact: 'Contact'
},
form: {
validation: {
required: 'This field is required',
email: 'Please enter a valid email'
}
}
}
}
API Reference
useTranslations()
Returns an object with:
-
t(key, variables?)- Translation functionkey: Translation key (dot notation supported)variables: Optional object with variable substitutions- Returns: Translated string or key if not found
-
locale- Current locale (reactive ref)- Type:
Ref<string> - Reactive property that updates when locale changes
- Type:
-
setLocale(locale)- Change current localelocale: New locale string- Triggers reactivity for all components using translations
Plugin Options
interface MazUiTranslationsOptions {
locale?: string // Default locale (default: 'en')
translations?: Record<string, Partial<MazUiTranslations>> // Custom translations
}
Type Definitions
interface MazUiTranslationsInstance {
locale: Ref<string>
t: (key: string, variables?: Record<string, any>) => string
setLocale: (locale: string) => void
}
interface MazUiTranslations {
select: { noOptions: string }
input: { required: string }
datePicker: { placeholder: string }
// ... other component translations
}
Default Translations
The package includes default English translations for Maz-UI components. You can override any of these by providing your own translations.
Default Structure
const defaultTranslations = {
select: {
noOptions: 'No options available'
},
input: {
required: 'This field is required'
},
datePicker: {
placeholder: 'Select date...'
}
}
Adding New Languages
app.use(MazUiTranslationsPlugin, {
locale: 'fr',
translations: {
fr: {
checklist: {
noResultsFound: 'Aucun résultat trouvé',
searchInput: {
placeholder: 'Rechercher',
},
},
// etc...
},
de: {
checklist: {
noResultsFound: 'Keine Optionen verfügbar',
searchInput: {
placeholder: 'Suchen',
},
},
// etc...
}
}
})
License
MIT License - see LICENSE file for details.
Related Packages
@i18n-micro/hmr
Translation HMR utilities for Nuxt I18n Micro (granular subpath imports).
51,795
251
@i18n-micro/node
Node.js utilities for loading translations and locale data in Nuxt I18n Micro.
4,423
251
Version History
| Version | Released | License |
|---|---|---|
| 5.0.0 | MIT | |
| 4.9.2 | MIT | |
| 4.8.0 | MIT | |
| 4.7.6 | MIT | |
| 4.7.4 | MIT | |
| 4.7.3 | MIT | |
| 4.7.2 | MIT | |
| 4.7.0 | MIT | |
| 4.6.1 | MIT | |
| 4.5.0 | MIT | |
| 4.3.0 | MIT | |
| 4.2.1 | MIT | |
| 4.2.0 | MIT | |
| 4.1.8 | MIT | |
| 4.1.7 | MIT | |
| 4.1.3 | MIT | |
| 4.1.2 | MIT | |
| 4.1.1 | MIT | |
| 4.0.0 | MIT |
Pre-releases (55)
| Version | Released | License |
|---|---|---|
| 5.0.0-beta.50 | MIT | |
| 5.0.0-beta.46 | MIT | |
| 5.0.0-beta.44 | MIT | |
| 5.0.0-beta.39 | MIT | |
| 5.0.0-beta.28 | MIT | |
| 5.0.0-beta.25 | MIT | |
| 5.0.0-beta.24 | MIT | |
| 5.0.0-beta.18 | MIT | |
| 5.0.0-beta.17 | MIT | |
| 5.0.0-beta.11 | MIT | |
| 5.0.0-beta.9 | MIT | |
| 5.0.0-beta.8 | MIT | |
| 5.0.0-beta.6 | MIT | |
| 5.0.0-beta.5 | MIT | |
| 5.0.0-beta.4 | MIT | |
| 5.0.0-beta.3 | MIT | |
| 5.0.0-beta.2 | MIT | |
| 5.0.0-beta.1 | MIT | |
| 5.0.0-beta.0 | MIT | |
| 5.0.0-canary.ef64a02.0 | MIT | |
| 5.0.0-canary.07195c6.0 | MIT | |
| 4.9.2-beta.0 | MIT | |
| 4.7.10-beta.0 | MIT | |
| 4.7.6-beta.0 | MIT | |
| 4.7.0-beta.1 | MIT | |
| 4.7.0-beta.0 | MIT | |
| 4.3.0-rc.0 | MIT | |
| 4.3.0-alpha.1 | MIT | |
| 4.2.1-beta.0 | MIT | |
| 4.2.1-alpha.10 | MIT |
Showing the latest 30 of 55. See every release on npm