janko / rodauth-i18n

I18n integration and translations for Rodauth authentication framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

make generate rodauth:i18n:translations load translations from other rodauth plugins

HoneyryderChuck opened this issue · comments

commented

(this picks up on a discussion from #2 to hopefully keep the discussion segregated).

I'd like to suggest extending the rodauth:i18n:translations rails generator to pick up translations from other rodauth plugins and merge them all into one single rodauth.{lang}.yml file (currently, it copies the rodauth-i18n translations only into the dir where rails is expected to load translations from).

Quoting @janko comment from the linked issue:

Good catch, not at the moment. I'm not sure if it's better to create a new file (e.g. rodauth-oauth.en.yml) or merge translations into rodauth.en.yml (more difficult). In case of the former, rodauth-i18n would somehow need to know the name of the gem registering its translations.

After thinking about this a bit more, I think that it's cleaner (even if more difficult) and merge all translations there. rodauth-i18n seems to be in a particularly "privileged" place, as all plugins can pick up on it by adding their own translations, while it not having to be a direct plugin dependency. In this way, I think it makes sense to merge them (all rodauth plugin translations) all into one file, conceptually.

The implementation could traverse all files from dirs in Rodauth::I18n.directories, load each file one by one, merge all yaml-decoded translaations from the selected locales into their own hashes, then yaml-encode-then-write into the destination rodauth.{lang}.yml file.

In this way, I think it makes sense to merge them (all rodauth plugin translations) all into one file, conceptually.

What happens when the user has imported translations, edited them, and then added rodauth-oauth and wants to import their translations? By default, the content of locale files would be replaced, unless we think of a smarter append strategy.

The implementation could traverse all files from dirs in Rodauth::I18n.directories, load each file one by one, merge all yaml-decoded translaations from the selected locales into their own hashes, then yaml-encode-then-write into the destination rodauth.{lang}.yml file.

That sounds reasonable, though it has the issue I mentioned earlier.

commented

That's a good point. I think the algorithm described above could be extended to do the following:

  1. traverse all files from dirs in Rodauth::I18n.directories
  2. load each file one by one, merge all yaml-decoded translations from the selected locales into their own hashes,
  3. if there's a rodauth.{lang}.yml file available, load and merge to the hash above (should keep local possibly-edited translations)
  4. encode and write to file

This has been implemented in #5 and released in version 0.3.1 🙂