ruipin/fvtt-lib-wrapper

Add localization

Closed this issue · 6 comments

Is your feature request related to a problem, e.g. with a module? Please describe.
Currently there is no way to localize text for other languages. All settings of libWrapper are displayed in English invariant of what the games language is set to. This can be problematic for people that are not fluent in the English language.

Describe the solution you'd like
Implement foundries default solution for translation using the i18n framework. Specify translation and keys in dedicated files, each containing the translation for a specific local.

Describe alternatives you've considered
There really is no alternative. It would simple improve accessibility for the user.

Additional context
I do understand why libWrapper itself does not prioritize translations, however I would still emphasize that the amount of work to localize the project is minimal and actual translations can be done by the community.

Thanks for the feature request.

You're right, this is something I have considered in the past, but as a library my focus so far has been in getting the core functionality up and running, so I wasn't too worried about localisation.

I agree that this module has gotten to a point where localisation is indeed worth pursuing. I will need to look into the i18n framework (haven't really done anything with it before).

Do you by any chance have any examples that I can reference? Otherwise I'll see if I can ask around on Discord.

https://gitlab.com/woodentavern/foundryvtt-bar-brawl

In the module.json you specify the language files They are usually under module/lang

"languages": [
    {
      "lang": "de",
      "name": "Deutsch",
      "path": "lang/de.json"
    },
    {
      "lang": "en",
      "name": "English",
      "path": "lang/en.json"
    }
  ],

All you then need to do is in the code reference the key in the json so: game.i18n.localize("libwrapper.settings.example"):

The content of the lang files would look like this:

{
 "libwrapper": {
   "settings": {
      "example": "This is the button text",
      "exampleHint": "This is the hint to what the button actually does",
   }
  }
}

Its pretty simple, the rest will foundry manage for you.

Sounds good, thanks!

What happens if a key doesn't exist for a particular language (e.g. I added new text to the english json, but didn't update the translations since I can't speak those languages), I assume it just takes the english translation?

And what about Handlebars, is there a helper there or are we expected to write {{game.i18n.localize('xyz')}} everywhere?

Anyway, my current plan is to pursue this after (or at the same time as) I find the time to clean up more of #42 since that will trigger multiple changes to the messages output by libWrapper.

if there is no key available it should fallback to the default (EN) language.

handlebars has a helper {{ localize "libwrapper.settings.example" }}

Adding to this ticket so I have it all tracked in the same place.

The Foundry VTT documentation has this page: https://foundryvtt.com/article/localization/
The Foundry localization API is documented in: https://foundryvtt.com/api/Localization.html

This is now implemented in v1.10.0.0.

See the english JSON file. Contributions for other languages are welcome.