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

[2.1] Load Messages from other than file #2232

Conversation

pdobrigkeit
Copy link
Contributor

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)

…iguration option. Default stays the same.

Introduced new option to translation_patterns => is_file (Default: true)
@travisbot
Copy link

This pull request passes (merged d8b3226 into 0598a05).

… are present, otherwise translate would just return an array
@travisbot
Copy link

This pull request fails (merged 9ad3eeb into 0598a05).

@@ -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
Copy link
Member

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.

@DASPRiD
Copy link
Member

DASPRiD commented Aug 24, 2012

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.

@DASPRiD DASPRiD closed this Aug 24, 2012
@pdobrigkeit
Copy link
Contributor Author

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?

@DASPRiD
Copy link
Member

DASPRiD commented Aug 24, 2012

You actually do have to care, as you are working with ordinal numbers in that case.

@pdobrigkeit
Copy link
Contributor Author

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:

"comment" => array(0 => "comment", 1 => "comments")

and do

$translator->translatePlural('comment', 'comments', $numberOfComments);

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

$translator->translate($nameOfEntry)

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?

@DASPRiD
Copy link
Member

DASPRiD commented Aug 24, 2012

No, what you do is the following:

'comment' => array('%d comment' /*or: 'one comment'*/, '%d comments')

By the way, if you have further questions, I'd suggest to discuss them in #zftalk.2 on freenode.

@pdobrigkeit
Copy link
Contributor Author

That doesn't solve the problem that the keyword 'comment' can now no longer be used for any other application area?

@DASPRiD
Copy link
Member

DASPRiD commented Aug 24, 2012

Ah well, because I took your example there. it should surely be:

'%d comment' => array('%d comment' /*or: 'one comment'*/, '%d comments')

@pdobrigkeit
Copy link
Contributor Author

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:

sprintf($translator->translatePlural('%d comment', '', $numberOfComments), $numberOfComments);

which is not yet very pretty, but at least I do not have conflicting keywords in the language files

@DASPRiD
Copy link
Member

DASPRiD commented Aug 24, 2012

Well, actually what you do is:

sprintf($translator->translatePlural('%d comment', '%d comments', $numberOfComments), $numberOfComments);

That's pretty the same what you do with gettext. In case a translation is missing, it will use those two source strings.

@pdobrigkeit
Copy link
Contributor Author

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

$key = '%d ' . $name;
sprintf($translator->translatePlural($key, $key . 's', $number), $number);

and I will be fine and still be able to use the keyword without '%d' for the regular translations. Very cool.

@DASPRiD
Copy link
Member

DASPRiD commented Aug 24, 2012

Well, it's not always that easy, you surely may want to read a bit into translations.

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

Successfully merging this pull request may close these issues.

3 participants