Skip to content
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

Skip translation when source language equals target language #4

Open
wants to merge 1 commit into
base: glossary
Choose a base branch
from

Conversation

yoshih
Copy link
Collaborator

@yoshih yoshih commented Aug 25, 2022

Closes https://github.com/denkungsart/castupload/issues/7426

@andreas-venturini
Julia had the error again. Unfortunately it only seems to happen occasionally.
So I can not say for sure this bug is fixed now.
I'd suggest to merge the change and see if it happens again (which I can't imagine).

Copy link
Member

@andreas-venturini andreas-venturini left a comment

Choose a reason for hiding this comment

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

@jjinkxy I don't want to merge this without knowing what is actually being accomplished - so when you have this problem next please switch to this branch locally and see if this helps solve your problem (Edit by Julia: set to this branch in gemfile to check if this fixes my problem the next time it arises.)

@yoshih yoshih force-pushed the castupload-7426-fix-target-langs branch 6 times, most recently from 37f84cf to c5d8348 Compare September 14, 2022 17:02
@yoshih yoshih force-pushed the castupload-7426-fix-target-langs branch from c5d8348 to c9ff80c Compare September 14, 2022 17:08
@yoshih
Copy link
Collaborator Author

yoshih commented Sep 14, 2022

@andreas-venturini
I just ran into the same error. It occurs when you translate e.g. from=en, and removed a key from there before which is present in other locale files.
I simply added the error to the rescue statement, I can confirm this fixes the bug.
The key in the source locale is then added back as key: ''.

Copy link
Member

@andreas-venturini andreas-venturini left a comment

Choose a reason for hiding this comment

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

I just ran into the same error. It occurs when you translate e.g. from=en, and removed a key from there before which is present in other locale files.

So the problem is inconsistent source files (i.e. keys missing in the source language but not in the target language)

I'm not sure this is a use case we need to support - as we generally discourage editing the translation files manually. E.g. when using i18n-tasks rm to remove outdated translations this problem can never happen.

Can we perhaps check with i18n-tasks missing if a key is missing (in the source) and if so raise & instruct to fix this inconsistency before proceeding with the translate ?

@yoshih
Copy link
Collaborator Author

yoshih commented Sep 15, 2022

Can we perhaps check with i18n-tasks missing if a key is missing (in the source) and if so raise & instruct to fix this inconsistency before proceeding with the translate ?

Not sure about using i18n-tasks for this. But maybe we could catch the Google error and raise our own.
"Inconsistency in source file" or something like this.

I think we could also raise an error when source language equals target language, maybe this is more specific.

@andreas-venturini
Copy link
Member

I think we could also raise an error when source language equals target language, maybe this is more specific.

This would be better - but how would this solve the problem though?

It occurs when you translate e.g. from=en, and removed a key from there before which is present in other locale files.

@yoshih
Copy link
Collaborator Author

yoshih commented Sep 15, 2022

This would be better - but how would this solve the problem though?

When source and target language are equal, which Google doesn't like, this seems to occur only in the case I described above. We could make the error message more specific to point out that a key in the source file is missing.

@andreas-venturini
Copy link
Member

I think I still don't understand sorry. Is the missing key in the source file the problem or not? If not it wouldn't make sense to have customize this error message.

I.e. can this problem happen when there is a missing key and target language is not equal to source language?

@yoshih
Copy link
Collaborator Author

yoshih commented Sep 15, 2022

Btw:
I accidentally found out, that my fix with the rescue statement would provide the same result as we didn't use glossary translation (with our easy translate master).
I removed the key agency: Agency from EN, the result after translation is agency: ''.

I.e. can this problem happen when there is a missing key and target language is not equal to source language?

I'm not sure I understand. When I translate from EN and in DE the key is missing, this would be our usual use case?

Not sure how this works in detail, but I think the problem is, that translating back to the source language doesn't work, because Google receives "from EN" and "to EN", which is not allowed.

@yoshih
Copy link
Collaborator Author

yoshih commented Sep 15, 2022

Is the missing key in the source file the problem or not?

Yes, that's the only case I could reproduce the error with.

@jjinkxy
Copy link
Collaborator

jjinkxy commented Nov 9, 2022

@jjinkxy I don't want to merge this without knowing what is actually being accomplished - so when you have this problem next please switch to this branch locally and see if this helps solve your problem

This problem came up again:

➜  prestage git:(18065-add-skill-to-sports) ✗ dotenv -f ".env.development" i18n-tasks translate-missing --from=de
#StandWithUkraine
/Users/juliajochum/.rvm/gems/ruby-3.0.4/gems/google-cloud-translate-v3-0.4.2/lib/google/cloud/translate/v3/translation_service/client.rb:335:in `rescue in translate_text': 3:Target language can't be equal to source language.. debug_error_string:{"created":"@1668003251.457701000","description":"Error received from peer ipv4:142.250.185.106:443","file":"src/core/lib/surface/call.cc","file_line":953,"grpc_message":"Target language can't be equal to source language.","grpc_status":3} (Google::Cloud::InvalidArgumentError)

I tried this branch out and this fixed it. (I had set the :en translations already)

➜  prestage git:(18065-add-skill-to-sports) ✗ dotenv -f ".env.development" i18n-tasks translate-missing --from=de
#StandWithUkraine
Translated 11 keys
+--------+---------------------------------------------------------------------------------+--------------------+
| Locale | Key                                                                             | Value              |
+--------+---------------------------------------------------------------------------------+--------------------+
|   ca   | activerecord.attributes.actor_profile/search.sports_hash                        | Esports            |
|   ca   | activerecord.attributes.actor_profile/search.sports_operator                    | Operador esportiu  |
|   ca   | actor_profiles.form.placeholder_sports                                          | afegir esports     |
|   de   | activerecord.attributes.actor_profile/search.sports_in_conditional_ary          |                    |
|   de   | activerecord.attributes.actor_profile/search.sports_in_conditional_ary_operator |                    |
|   es   | activerecord.attributes.actor_profile/search.sports_hash                        | Deportes           |
|   es   | activerecord.attributes.actor_profile/search.sports_operator                    | operador deportivo |
|   es   | actor_profiles.form.placeholder_sports                                          | añadir deportes    |
|   fr   | activerecord.attributes.actor_profile/search.sports_hash                        | Des sports         |
|   fr   | activerecord.attributes.actor_profile/search.sports_operator                    | Opérateur sportif  |
|   fr   | actor_profiles.form.placeholder_sports                                          | ajouter des sports |
+--------+---------------------------------------------------------------------------------+--------------------+

TL;DR
Solution worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants