-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Translations without Meteor #5514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Updates to latest i18next and uses more standard loading pattern Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
No longer used Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
and marketplace language code Signed-off-by: Eric Dobbertin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reviewing, but a couple question so far about namespaces
| @@ -3,7 +3,7 @@ | |||
| "i18n": "en", | |||
| "ns": "reaction-stripe", | |||
| "translation": { | |||
| "reaction-payments": { | |||
| "reaction-stripe": { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment for all translation files in this package: Should this be reaction-payments-stripe or just payments-stripe to match the package name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's supposed to match ns in this same file, so that's why I changed it. There were a few files that were probably copied and were not validly formatted, which didn't matter with the way we were loading before, but now caused errors.
I didn't give much thought to what the namespace should be other than fixing the mismatch bug. I think the general rule would probably be to match identically the package name, but our package names are also a bit inconsistent.
@mikemurray Do you foresee any problems if I audit these namespaces and ensure they exactly match the package names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be fine to make them match the package. As far as I remember, the name is supposed to match the package anyway, and things may have gotten out of sync with all the copy-pasting of translations around the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing all, they actually do all match the package names. So we should try to improve the consistency of the package names, but that's something I won't tackle here.
| @@ -3,7 +3,7 @@ | |||
| "i18n": "en", | |||
| "ns": "example-paymentmethod", | |||
| "translation": { | |||
| "reaction-payments": { | |||
| "example-paymentmethod": { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment for all translation files in this package: Should this be reaction-payments-example or just payments-example to match the package name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion in the other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is a great PR!
Finished my code review, a few other comments but nothing blocking.
Started the develop branch, then switched to yours and everything seems to work as it should.
Love that you can see the updates in real time now instead of having to refresh the translations.
| async up() { | ||
| const { Assets } = rawCollections; | ||
|
|
||
| await Assets.deleteMany({ type: "i18n" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration worked by deleting all the content of the Migrations collection, but should the collection itself also be removed? Or do we want to leave a blank Translations collection in the database?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I can do dropCollection instead.
| import ReactionError from "@reactioncommerce/reaction-error"; | ||
| import { Shops } from "/lib/collections"; | ||
|
|
||
| // We should be able to publish just the enabled languages/currencies/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this comment is relevant anymore.
|
|
||
| const defaultLanguage = shop.language; | ||
|
|
||
| if (language === defaultLanguage && !enabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use the "all languages" toggle, the default language (English in my case) stays enabled, but I am able to turn off English if I toggle it individually.
When I refresh the page, English is still enabled, so this seems to just be a UI issue that no error is shown.
I don't think a blocker for this, but if it's an easy fix I'd tackle it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see if it's easy to show the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f9c6358 and fixed for the currency list, too.
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
Signed-off-by: Eric Dobbertin <[email protected]>
|
@aldeed In some custom plugins I have I'm seeing this error Should we consider a method of deprecating the old implementation rather than a hard breaking change? Maybe at the least have the file just mock the methods used and log a useful message for upgrading? |
Impact: minor
Type: feature
Issue
Reaction Admin i18next loads translations from a Translations collection, loaded by a Meteor DDP subscription. We are trying to remove the Meteor dependency from the API.
Solution
i18ncore plugin) now provides translations, merged from all plugins, at the standard/locales/resources.jsonroute.i18ncore plugin) also provides a/locales/namespaces.jsonroute, which returns the namespaces array. The i18next client library needs this list for initialization.no-meteorfolder and no longer useloadTranslationsfunction. Instead, they pass translations array toregisterPluginwithin ani18nobject./private(this was a Meteor thing). Those translations have been moved intocoreplugin.Translationscollection on startup, no longer publishes that collection, and no longer supports "flushing" translations because they are now always automatically up to date.Translationscollection.Other changes
lng=<code>in your query string. For example,http://localhost:3000/operator/?lng=enor
http://localhost:3000/operator/?lng=en-USwill show you English text even if your browser language is set to something else.shop/getLocalMeteor method is removed.Breaking changes
loadTranslationsto load translations will need to be updated to pass them toregisterPlugininstead. See the built-in plugins for examples.shop/getLocaleMeteor method or usingReaction.Localeobject will need changes.i18next.languageshould be used to get the detected/default language.Testing