Skip to content

Live chat widget: let the host page choose the UI language #657

Description

@sunyinghao5438

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)

  1. 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.
  2. 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.
  3. 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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions