-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Crowdin Bridge: Fix locale vs LanguageId #50040
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
pculka
commented
Apr 17, 2023
Q | A |
---|---|
Branch? | 6.2 |
Bug fix? | yes |
New feature? | no |
Deprecations? | no |
Tickets | Fix #... |
License | MIT |
Doc PR | symfony/symfony-docs#... |
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
@@ -109,6 +109,25 @@ public function read(array $domains, array $locales): TranslatorBag | |||
$translatorBag = new TranslatorBag(); | |||
$responses = []; | |||
|
|||
$localeLanguageMap = []; | |||
foreach ($this->listLanguages($locales) as $language) { |
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.
this method doesn't accept any arguments
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.
Probably it would be better to extract this to a separate method, e.g. mapLocaleToLanguageId
or something like this
@@ -118,7 +137,7 @@ public function read(array $domains, array $locales): TranslatorBag | |||
|
|||
foreach ($locales as $locale) { | |||
if ($locale !== $this->defaultLocale) { | |||
$response = $this->exportProjectTranslations($locale, $fileId); | |||
$response = $this->exportProjectTranslations($localeLanguageMap[$locale], $fileId); |
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 same issue probably is also relevant for the uploadTranslations
method
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.
Actually from my observation the mapping is done on Crowdin side and works (i.e. de-DE source gets properly mapped to de)
Hi @pculka, could you please provide locale examples than currently can't be synced with Crowdin? |
The failed Unit tests do not expect the GET languages call, you should include the mock for this call in the tests |
Hi @andrii-bodnar - In our project we use full locale codes, not language codes. For example for Germany the full locale is de-DE. This is in languages endpoint of Crowdin is stated as locale attribute:
When downloading translations in your code - you also properly annotated that the requested parameter has to be LanguageID, but you pass in locale and that fails. If I pass locale, I have to find the correct language ID by the locale and then the languages will be downloaded. |
I'll try to add GET for the mock |
@pculka got it, the current approach might be unreliable since a user can use a different language code format and in this case it's hard to guess the right language ID. I would suggest encouraging users to use Language Mapping in this case. The flow:
This will not break any existing integrations and will allow customizing the used language codes. By the way, something similar is suggested for the other translation provider here - https://symfony.com/doc/current/translation.html#installing-and-configuring-a-third-party-provider |
Well I think the core problem lies in misunderstanding and misdocumentation of how to use locales should be used within symfony itself. It tends to be easy to confuse code vs locale vs osxlocale, etc. That's why I ended up here, as I was using proper i18n locale string, but in communication with CrowdIn the expected parameters are Language IDs. Anyway I've added the mapping, in get project info I now have:
You suggest I change this code I provided to check for the project languageMapping setting and just fix it that way, right? |
@pculka does Symfony has some language codes list that is recommended to use for translation catalogs? |
I doubt it. both 'de' and 'de-DE' are valid locale strings, both referencing german language, but -DE specifies also the region which is optional. I mean. Meaning de-DE should try automatically a fallback maybe? Not sure how to tackle this situation properly. |
Well, the Language Mapping approach might be more complicated. Probably we can keep the suggested approach in this case and not overcomplicate this for now |
added one more fallback for underscore locale (you had that in one of your tests), and tests are passing. |
and refactored - extracted the mapping function out |
@nicolas-grekas please can you check this PR? I also noticed a failed test in appveyor, 1) Symfony\Component\Messenger\Bridge\Redis\Tests\Transport\RedisExtIntegrationTest::testGetAfterReject something in terms of redis. Maybe there is a problem with redis.dll for windows, which is not compiled for 8.2 - If it is needed, I compiled a working redis.dll for 8.2.5 for x64 both ts and nts versions: https://github.com/pculka/phpredis/releases/tag/5.3.7 But if it is possible to merge without passing appveyor, it would be great to get this done (and if @andrii-bodnar agrees) |
b4f4695
to
38ce6c3
Compare
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'm going to trust you on this one :)
src/Symfony/Component/Translation/Bridge/Crowdin/CrowdinProvider.php
Outdated
Show resolved
Hide resolved
Thank you @pculka. |
…i-bodnar) This PR was submitted for the 6.4 branch but it was merged into the 6.3 branch instead. Discussion ---------- [Translation][Crowdin] Use project language mapping | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Sometimes the locale codes may be different from the [codes](https://developer.crowdin.com/language-codes/) used in the Crowdin API. This will cause API errors because the wrong code is passed in the upload and download translation requests. There was already a fix (#50040), but it only works partially. The suggested approach uses the [language mapping](https://support.crowdin.com/project-settings/#languages) configured in the Crowdin project. If the locale code and the crowdin code are different, the user needs to configure the language mapping in the Crowdin project. Documentation - symfony/symfony-docs#19325 Commits ------- a1d2f67 [Translation] Crowdin Bridge: use the project language mapping