Skip to content

Conversation

@ChristophWurst
Copy link
Contributor

This seems like a trivial change. But it took me ages to figure out. Anyway …

What it does is

  • Use a getttext-based translation approach, just like we use in other Nextcloud code
  • Have a script that extracts the strings (no more fragile php script)
  • Is able to just read the raw .pot files
  • Bundle translations statically (no dynamic import necessary. overhead minimal due to low number of strings)
  • Dynamically decide which locale to use (based on Nextcloud's locale or 'en')

For technical reasons I had to switch from a simple Babel+Typescript system to one with Webpack in order to do the locale bundling. This also forced me to switch from Jest to Mochapack. But that works just as fine. The tests here are trivial.

Once https://docs.transifex.com/transifex-github-integrations/github-tx-ui is set up (having my fingers crossed that this actually works), I'll add some integration tests for different locales. But manually adding an en.pot allowed me to test translation successfully.

@nextcloud/javascript please have a look. I would like to use this approach for https://github.com/nextcloud/nextcloud-vue as well.

Fixes #1

@nickvergessen
Copy link

You ment to make us all review this not work on it, right?

@ChristophWurst
Copy link
Contributor Author

You ment to make us all review this not work on it, right?

I meant to have you work on the review :)

@rullzer rullzer merged commit 88c4b8e into master Feb 13, 2020
@delete-merged-branch delete-merged-branch bot deleted the enhancement/gettext branch February 13, 2020 09:29
LOCALES.map(data => {
gt.addTranslations(data.locale, 'messages', data.json)
})
gt.setLocale(locale)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use the language settings for this instead of the locale setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never sure. @nickvergessen knows best

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well see nextcloud/server#14784

So moment JS is actually "fucked up" as it has only one option to set this and is unable to handle a locale being different from the language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then it should be fine for now otherwise it would just be the "seconds" which would be in the proper language, the rest provided by moment would have the language defined by the locale.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

L10n

6 participants