What
Let the page that embeds the widget tell it which UI language to use:
window.initLibredesk({ baseURL, inboxID, language: 'zh-CN' })
// later, when the host app's own language switch changes:
window.Libredesk.setLanguage('de-DE')
Why
Apps that embed the widget often have their own language switcher (ours is a SaaS dashboard in English, Chinese, German and Italian). Today the widget's language is either the inbox's fixed language or auto (the browser's navigator.language). So a user who picks Chinese in our app but has an English browser gets an English widget, and the other way round. The host app knows which language the user chose; the widget has no way to be told.
Proposed implementation (small, backwards compatible, no server changes)
static/widget.js: accept an optional config.language and pass it to the iframe as &lang=<code>, next to inbox_id and parent_origin. Add setLanguage(code), which posts { type: 'SET_LANGUAGE', language } to the iframe.
frontend/apps/widget/src/main.js: if lang is one of the codes from GET /api/v1/lang, use it; a bare primary tag also matches (zh → zh-CN, de → de-DE). Otherwise keep today's resolution.
App.vue: handle SET_LANGUAGE like the other parent messages. Load the strings with api.getLanguage(code) and switch the i18n locale in place, so an open conversation isn't reset.
Widgets that don't pass language behave exactly as they do now.
Open question: should the host's language also override an inbox set to a fixed language? My suggestion is to apply it only when the inbox is on auto, so an admin's explicit choice still wins. Happy to go either way.
If this fits the project's direction, I'm happy to send a PR (about 30 lines plus tests).
What
Let the page that embeds the widget tell it which UI language to use:
Why
Apps that embed the widget often have their own language switcher (ours is a SaaS dashboard in English, Chinese, German and Italian). Today the widget's language is either the inbox's fixed language or
auto(the browser'snavigator.language). So a user who picks Chinese in our app but has an English browser gets an English widget, and the other way round. The host app knows which language the user chose; the widget has no way to be told.Proposed implementation (small, backwards compatible, no server changes)
static/widget.js: accept an optionalconfig.languageand pass it to the iframe as&lang=<code>, next toinbox_idandparent_origin. AddsetLanguage(code), which posts{ type: 'SET_LANGUAGE', language }to the iframe.frontend/apps/widget/src/main.js: iflangis one of the codes fromGET /api/v1/lang, use it; a bare primary tag also matches (zh→zh-CN,de→de-DE). Otherwise keep today's resolution.App.vue: handleSET_LANGUAGElike the other parent messages. Load the strings withapi.getLanguage(code)and switch the i18n locale in place, so an open conversation isn't reset.Widgets that don't pass
languagebehave exactly as they do now.Open question: should the host's language also override an inbox set to a fixed language? My suggestion is to apply it only when the inbox is on
auto, so an admin's explicit choice still wins. Happy to go either way.If this fits the project's direction, I'm happy to send a PR (about 30 lines plus tests).