GlenDC / bucket

a positive goal tracker with clear focus
https://bckt.xyz
GNU General Public License v3.0
0 stars 0 forks source link

Implement custom localisation module #19

Closed GlenDC closed 3 years ago

GlenDC commented 3 years ago

Inspiration: https://github.com/toastal/elm-translation-example

GlenDC commented 3 years ago

Instead of implementing it myself, I might safe time with https://korban.net/elm/catalog/packages/ui/i18n, just need to ensure that they can implement their custom rules in language files. Which I doubt.

Locale negotiation might never the less be useful: https://package.elm-lang.org/packages/wolfadex/locale-negotiation/latest/

GlenDC commented 3 years ago

Look also in js Intl for localisation

GlenDC commented 3 years ago

Intl will be integrated via ports to our Elm code.

To get the locale we can write a port function such as:

const getBrowserLanguages = () => {
  if (navigator.languages && navigator.languages.length) {
    return navigator.languages;
  } else {
    return [navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en'];
  }
}
GlenDC commented 3 years ago

Started core implementation in dd54639d6142a2d72d26a3486e07edba8110b5d4.

Still TODO:

In order to detect languages I'll have to write JS ports code. That I'll have to have duplicate for both projects I'm afraid.

GlenDC commented 3 years ago

Localisation module is fully implemented in https://github.com/plabajo/bucket/commit/c88d8197d4c0cb93f6f99c915edd8619361f7e31. Elm website (static) is now also auto translated based on browser language (tested with English and partial Dutch).

Elm App (elm-spa) is not yet switching language, but that is something we can hook up as well, once we get to actually developing the app. At this point there is no need to worry any further I would say.