-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[2.1] Load Messages from other than file #2232
[2.1] Load Messages from other than file #2232
Conversation
…iguration option. Default stays the same. Introduced new option to translation_patterns => is_file (Default: true)
… are present, otherwise translate would just return an array
@@ -282,6 +283,11 @@ public function translate($message, $textDomain = 'default', $locale = null) | |||
$locale = ($locale ?: $this->getLocale()); | |||
$translation = $this->getTranslatedMessage($message, $locale, $textDomain); | |||
|
|||
//allow use of translate if plurals are present |
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.
First of, this should be a separate PR. Second, I'm against this at all. What I'd agree to though is that a check should be made that a string is actually returned.
I'd argue that this does actually not fit into the terms of patterns (which are meant to be file patterns). This should likely not be put into the existing translation modes (pattern/file) at all. Some better way could be possible which I already have in mind, but that would mean a BC break. Closing for now. |
Very well. I still argue for the translatePlural and translate transparency. As a developer you should not need to know which of the functions you have to call. If I just want the translation of a certain String I do not care if there are other forms available. And in that case I would get an array. I admit am quite new to using plural forms, but I want to improve my own skillset. Is is common practice to have different keys for the plural available forms? |
You actually do have to care, as you are working with ordinal numbers in that case. |
But I have the same message-key? Let's say I have a DB full of keywords. Now I have a Blog that has Comments. I want to be able to have a message "0 comments", "1 comment" and "2 comments" underneath each blog entry. Thus I would add the following structure to my language file:
and do
which will work fine. In my backend I have an admin panel where one can manage the navigation and add pages. The navigation is multilangual and the user can name the Entry which will get translated automatically. To do so I call
If the user would call an entry now 'comment' nothing would work as expected but the user would get errors because the return of the call is an array and not a string. In my expectation I would want that both translate and translatePlural return only a string and for example if I request a translatePlural when none is available but the keyword is set, I would not throw an exception, but return the string that is set? |
No, what you do is the following:
By the way, if you have further questions, I'd suggest to discuss them in #zftalk.2 on freenode. |
That doesn't solve the problem that the keyword 'comment' can now no longer be used for any other application area? |
Ah well, because I took your example there. it should surely be:
|
Ah, alright. That would make more sense. Because than I also have a criteria on which I know that I would have to use the translate or the translatePlural function. Because afterwards I do something like:
which is not yet very pretty, but at least I do not have conflicting keywords in the language files |
Well, actually what you do is:
That's pretty the same what you do with gettext. In case a translation is missing, it will use those two source strings. |
Thank you very much for clarifying a couple of things for me. It is just the case that I usually see from a user perspective and my users should not have to type '%d foo' somewhere, but in that case I see now that I can construct the key very easily from the supplied string (which would be 'comment') and in cases where I am aware of Plural things I would just do
and I will be fine and still be able to use the keyword without '%d' for the regular translations. Very cool. |
Well, it's not always that easy, you surely may want to read a bit into translations. |
Added the possibility to load messages from other than files via configuration option. Default stays the same.
Introduced new option to translation_patterns => is_file (Default: true)