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 are included in the main bundle because they cover ~95 % of the current traffic. The other 7 locales are loaded in lazy chunks the first time a user activates the widget on that locale, keeping the initial bundle below 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. Any missing key in a translation falls back to the English string (en acts as the base).

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 merged on top of the active locale bundle (deep merge):

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 the locale, destroy the instance and re-mount it with the new one:

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

Further reading