Pedal-Intelligence / saypi-userscript

An independent voice interface for Inflection AI's conversational assistant, Pi
https://www.saypi.ai/
Other
15 stars 3 forks source link

Translations not working on Safari #67

Closed rosscado closed 4 months ago

rosscado commented 4 months ago

The i18n.ts module is not loading internationalised messages in Safari on iOS. This is because the capability check for chrome.i18n passes but the subsequent call to chrome.i18n.getMessage fails, because chrome.i18n is an empty {} stub. There are other issues with the getMessage function too, in particular that its fallback mechanism relies on asynchronous operations but the function itself is not asynchronous. Solve by loading the message bundles on module initialisation so that getMessage can assume they've already been populated and proceed to read them synchronously.

rosscado commented 4 months ago

So it's not the case that translations don't work on iOS. They just don't work as expected for some unusual combinations of system language and region. In iOS, if you set your system language to Portuguese and your region to Ireland, and don't set any overrides for the Safari browser, you get a browser locale of pt-IE. Safari's implementation of i18n.getMessage is unable to map this to the pt_BR locale bundle, so falls back to en. The same goes for zh-IE. In effect, iOS users need to select a more typical language and region combination such as pt-BR or zh-CN for i18n.getMessage to work as expected in Safari.

Simpler locale bundles like de or fr work without complications, so even de-IE will resolve to de, it's only compound locale bundles like pt_BR or zh_CN that Safari struggles with.