Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Added translation to FormElementErrors view helper #104

Merged

Conversation

RalfEggert
Copy link
Contributor

Added the possibility to translate error messages which are not translated by validators. Added test case as well.

@MatthiasKuehneEllerhold
Copy link
Contributor

Isnt it possible that the error messages are translated twice then?

@akrabat
Copy link
Contributor

akrabat commented Feb 23, 2017

@MatthiasKuehneEllerhold Why do you think that they'll be translated twice?

@akrabat akrabat modified the milestones: 2.11.0, 2.10.0 Feb 23, 2017
@weierophinney weierophinney merged commit e84fe52 into zendframework:develop Dec 6, 2017
weierophinney added a commit that referenced this pull request Dec 6, 2017
Added translation to FormElementErrors view helper
weierophinney added a commit that referenced this pull request Dec 6, 2017
weierophinney added a commit that referenced this pull request Dec 6, 2017
@weierophinney
Copy link
Member

Thanks, @RalfEggert!

@MatthiasKuehneEllerhold
Copy link
Contributor

MatthiasKuehneEllerhold commented Dec 8, 2017

Sorry for answering this late. I totally forgot this.
We're using the zend-form view-helpers together with zend-validators. The zend-validator will translate the message upon raising a validation error. See AbstractValidator->error() calling AbstractValidator->createMessage() calling AbstractValidator->translateMessage().

This is contrary to all other translation handling: all other modules translate during the output, not during the adding of message to some queue / stack. But it is necessary in the zend-validator case to translate this early because of the placeholders that have to get replaced (e. g. %max% in the LessThan Validator) AFTER translating the template-message.

So what now happens (confirmed in #188):

  • The message template gets translated in the AbstractValidator
  • The placeholders in translated message template get replaced with their real values
  • The view helper translates the message again.

Depending how you set up your whole translation system this can either have no, minor or dramatic impact.
At our specific use case we're logging every message that couldnt get translated. So this will spam our error log with missing translations for already translated messages.
If the translated message (mit replaced placeholders) SOMEHOW matches the translation key of another translation, then you'll get the double translation that may change its text.
Let me give an example:

  • Message-Template in LessThan validator: "The input is not less than '%max%'"
  • Translated into german "Die Eingabe ist nicht kleiner als '%max%'"
  • Placeholders replaced: "Die Eingabe ist nicht kleiner als '5'"
  • Translation in view-helper: "Die Eingabe ist kleiner als '5'"

This example used this translation file:

return [
  "The input is not less than '%max%'" => "Die Eingabe ist nicht kleiner als '%max%'",
  "Die Eingabe ist nicht kleiner als '5'" => "Die Eingabe ist kleiner als '%'",
];

I admit this example is somewhat constructed (just to highlight the problem). It all depends on how you manage your translations. I've seen implementations with same-language translations (e. g. english => english).

If you're having none of the above, then you won't notice anything.

@froschdesign
Copy link
Member

@MatthiasKuehneEllerhold

havent confirmed it yet

Can you write an unit test that confirms the problem?

@MatthiasKuehneEllerhold
Copy link
Contributor

Yes: #188

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

Successfully merging this pull request may close these issues.

5 participants