-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add react.i18next and update project keywords for multi-language support #4190
Conversation
|
@mj-mehdizadeh is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
I highly recommend using ids (keys) for translations. Here is an in-depth discussion and answer on why ids instead of text makes sense opral/monorepo#599. <h2 className="inter-base-semibold">
- {t("Opt out of sharing my usage data")}
+ {t("sharing-data")}
</h2> In summary, using the reference text as key breaks apart as the project grows due to (but not limited to):
The management overhead of using text as ids outweighs the "but it's simpler for developers" benefit. The desire as a developer to see the reference text in source code can be achieved with vscode extensions like https://marketplace.visualstudio.com/items?itemName=inlang.vs-code-extension. |
Any news here? I would like to contribute with the spanish translation |
@mj-mehdizadeh do you have any plans to complete this great PR? Do you need help? |
@tsvetann I love to complete this, but it says Code owner review required, I don't know, what should I do? is there anything I can do? I thought it's needs to approved by Code owner. |
@mj-mehdizadeh I believe you've been asked to by the reviewer (@samuelstroschein ) to change the translation keys from free text to keys. Please look at his comment. So if I understand it correctly you should make this change and push again for a review. Let me know if you need further help. Thanks |
@tsvetann I am not a medusa member/not a reviewer. I commented to warn about the potential problems of using source text as id. If I would be a reviewer, I would request changes but I don't speak on Medusa's behalf. |
Yes but core components of the admin UI won't be translated. I mean, someone needs to translate those at some point 🤔 |
Agree. But if many plugins are translated maybe this puts more pressure on the core team to take the step |
@mj-mehdizadeh @samuelstroschein @tsvetann @georgerock @martinejaw @gempain Appreciate you all showing interest in the project, and huge props for this contribution, @mj-mehdizadeh 💜 My apologies for the slow response time. We've decided to move forward with the feature and approach in this PR with only minor adjustments:
This PR was closed, but @gempain continued the work in another fork. @gempain, will you lead the implementation of these requested changes? Also, let me know if you want to discuss anything. Happy to jump on a call. |
Thanks @olivermrbl for your attention and recognizing the community efforts. From my side the only topic is how to share the i18n instance with admin UI plugins so we can develop multilingual plugins. Thanks |
We will add support for translation files in plugins and admin extensions, e.g. Curious to hear what you think :) @kasperkristensen will likely be able to shed some more light on this, should it be necessary. |
@olivermrbl @kasperkristensen I might have a simpler solution for translating medusa plugins. We faced a similar problem for inlang plugins (discussion) and settled on a
Pros
In summary, an API definition. Nothing more, nothing less. Cons
|
@olivermrbl thanks a lot for your message ! Happy to take the lead on this. I can take a call pretty much any lunch time during the week, and I think a temporary Slack channel might help if we wanted to be more efficient. I'm having a hard time getting a dev setup to work properly without changing a few things, so I'd rather make sure I haven't missed something.
I think the changes you ask make perfect sense and are quite common patterns, I actually happen to have the same logic in a couple of projects so it shouldn't be hard to port here. @samuelstroschein's suggestion seems IMO a good approach. It will save the hassle of asking plugin maintainers to change translation logic whenever one day someone switches to something other than i18next. @samuelstroschein I think the cons you listed is not really a concern: plugins should be simple and independent enough that they can handle that complexity on their own without having to alter the translation config of the parent UI. That said, a solution to this would be to use a subscriber pattern where each plugin provides a stream of translations to the admin UI, which handles the registration of those translations to the i18next instance. Using something like interface Translations {
en: Record<string,string>;
// there's probably a way to use an enum instead of string, but you get the idea
[key: string]: Record<string,string>;
}
interface Plugin {
initI18n(): Promise<BehaviorSubject<Translations>>;
} const translations$ = new BehaviorSubject({ en: { hello: 'Hello' } });
export function initI18n() {
return translations$;
} and in the admin UI
Just pseudo code here of course and I haven't gone through the entire codebase to look where plugins are handled, but you get the idea. Let me know what you think ! |
Fantastic, thanks @gempain!
Tomorrow at 1 pm CET? I would love to hear more about your experience setting up the development environment so we can iron out all the issues and hurdles in the process. |
The interface Translations {
en: Record<string,string>;
// there's probably a way to use an enum instead of string, but you get the idea
- [key: string]: Record<string,string>;
+ [key: LanguageTag]: Record<string,string>;
}
We extracted our BCP-47 language tag library for types and validation which could be used, see https://github.com/inlang/inlang/tree/armageddon/source-code/core/language-tag |
Works for me ! How to initiate contact ? |
Yes but AFAIK TS won't let you use enums for index signatures. I checked your code here but this is TS syntax I've never encountered before. Interesting 😄 |
I'll reach out on X :) |
X 😱 😅 |
@gempain, haha - we can do whatever fits you best. Discord? |
No X works perfect, just found funny seeing someone for the first time say X instead of Twitter 😄 |
Why do you need/want enums? A type union seems sufficient.
The type are generated from JSON schema for runtime validation with https://github.com/sinclairzx81/typebox :) |
@mj-mehdizadeh I'm trying to find the most efficient way to move to keys without having to manually update each line you've already configured to use Edit: I was able to write a script that updates things for me using |
@mj-mehdizadeh, we will merge multi-language support this week – many thanks for your initial contribution. Without you and @gempain's efforts, we probably wouldn't have had an internationalized admin dashboard for a long time. I am sure this feature will bring joy to our community and users! |
Also, if you are up for it, we'd love to include your translations for fa-IR in a follow-up PR :) |
@samuelstroschein, this might be obvious, but how do you handle language variations e.g. en-US, en-GB using the BCP-47 specification? |
@olivermrbl "region tags" are supported by BCP-47. BCP-47 combines "subtags" such as regions into one tag. Hence, |
Cool, thanks! |
BCP-47 seems indeed to be the standard chosen: Do you want to rename the default to
IMO the language should always be written in its own languages ( Or is it okay to keep locales as display values for the dropdown ? |
Sure, we can go with en-US. I like that :)
Yeah, I just noticed the design had a human-readable display name. I think we should stick with just showing locales in the select. |
Are you handling copy/translations differently for the US? If not, I recommend choosing the language tag only ( |
@olivermrbl up to you, but I think @samuelstroschein suggestion makes sense. |
Yes sure - I don’t think it matters much at this point, so please go ahead with the one you find best :) |
Whoops I didn't notice we were in the old PR discussion. I'll move back to #4962. |
Pull Request: Update project keywords for multi-language support
Description:
This pull request updates the "admin-ui" keywords to support multi-language functionality. and I added the en-US, fa-IR languages, By modifying the keywords, the project becomes more discoverable and relevant to users who are searching for multi-language solutions.
Changes Made:
Reason for the Changes:
The addition of multi-language support is an important enhancement for this project. It enables users to easily find and identify the project as a suitable solution for their multi-language requirements. With these updated keywords, the project can reach a broader audience and increase its visibility in relevant search results.
Please review and merge this pull request to incorporate the updated keywords and improve the project's discoverability and relevance.
Screenshots or Additional Context: