Skip to main content

Internationalization

The widget supports 9 locales out of the box. The locale is selected with data-locale (auto-init) or config.locale.

Supported locales

CodeLanguageLoading
esSpanisheager (in the main bundle)
enEnglisheager
frFrenchlazy
deGermanlazy
itItalianlazy
ptPortugueselazy
caCatalanlazy
euBasquelazy
glGalicianlazy

es and en ship in the main bundle (widget/src/i18n/index.ts); the others are dynamically imported the first time they are used, keeping the initial bundle under 65 KB gzip.

Detection and fallback

  1. The widget reads config.locale/data-locale.
  2. If the value is not in SUPPORTED_LOCALES, it emits a console.warn and falls back to es.
  3. If a specific key is missing from the active locale bundle, the widget emits console.warn and returns the key itself (there is no automatic English fallback). The official translations (widget/src/i18n/<locale>.ts) cover the full key set, so this only affects you if you provide a malformed partial translations override.

Example

<script
src="https://cdn.neuroon.ai/widget@0.9.10/widget.js"
data-token="WIDGET_TOKEN"
data-container="#neuroon-search"
data-locale="ca"
async
></script>
window.NeuroonWidget.init({
container: '#neuroon-search',
token: 'WIDGET_TOKEN',
locale: 'eu',
})

Custom translations

You can override any subset of keys via config.translations. They are deep-merged on top of the active locale bundle:

window.NeuroonWidget.init({
container: '#neuroon-search',
token: 'WIDGET_TOKEN',
locale: 'es',
translations: {
search: {
placeholder: 'Buscar en nuestra ferretería…',
voiceButton: 'Buscar dictando',
},
results: {
empty: 'No tenemos eso. ¿Quieres que te avisemos cuando llegue?',
},
},
})

Switch locale at runtime

The current JavaScript API does not expose setLocale(). To change locale, destroy the instance and re-mount it:

const w = window.NeuroonWidget.getInstance('#neuroon-search')
w?.destroy()
window.NeuroonWidget.init({
container: '#neuroon-search',
token: 'WIDGET_TOKEN',
locale: 'fr',
})

Further reading