-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] added method to expose collected message #9859
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
Grygir
commented
Dec 25, 2013
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | no |
Fixed tickets | #2435 |
License | MIT |
Doc PR | symfony/symfony-docs#3386 |
@Grygir there's no need to create a new PR. You could've just pushed to your branch and PR would be updated. You have to merge master into your branch and resolve conflicts. Please add a PR description with a table. |
@jakzal thanks. That was a bit misunderstanding from my side. I've applied all changes for comments from #8597 and created a paragraph in symfony/symfony-docs#3386. |
@Grygir You should remove the merge commit (squashing you commits would help here). |
@@ -222,6 +222,56 @@ public function transChoice($id, $number, array $parameters = array(), $domain = | |||
return strtr($this->selector->choose($catalogue->get($id, $domain), (int) $number, $locale), $parameters); | |||
} | |||
|
|||
/** | |||
* Messages exposing |
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.
Should be something like: Collects all messages
.
@fabpot thanks, all commented issues are fixed. |
|
||
$domains = array_flip($domains); | ||
$messages = array(); | ||
for ($i = count($catalogues) - 1; $i >= 0; $i--) { |
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.
is it a good idea to do it with for? not foreach? You have flipped $domains
and left $catalogues
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.
$domains
is usually small array (several items) and $catalogues
is often quite big. So the for
-loop is used here (instead of array_flip
+ foreach
-loop) in only matter of performance.
You should update the CHANGELOG file (in the component dir) |
@aitboudad, do I understand correctly, this note should be in a section related to the coming version (2.5.0)? |
@aitboudad, done, thanks |
@wouterj pull request is updated, thanks |
👍 great! |
* | ||
* @return array | ||
*/ | ||
public function exposeMessages(array $domains = array(), $locale = null) |
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 don't really like the exposeMessages()
name. What about just getMessages()
?
@fabpot thank you, all comments are fixed (related symfony-docs pull request is updated as well) |
👍 |
Great work, @fabpot, nice to see this one picked up that fast! |
👍 |
* | ||
* @return array | ||
*/ | ||
public function getMessages(array $domains = null, $locale = null) |
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 don't see any difference between passing array()
and null
for domains. Then I would just use array $domains = array()
without null.
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 see @fabpot suggested that. But I don't agree with that. First of all, it makes the argument type dynamic and secondly, there is no semantic difference.
So when you see code like
$translator->getMessages(array());
$translator->getMessages(null);
you would think both do something different and look at the implementation what the difference is. But in fact it's the same.
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.
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.
Whatever. Use array()
if you want to, I don't really care.
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.
Please note what the default means: every domain. It seems wrong to use every domain if you pass an empty list. Null stands for no argument, if you pass no argument to domain, it seems logical to get all domains.
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.
@wouterj It's perfectly right to get every domain if you pass an empty list. The argument filters the required domains (see phpdoc), i.e. an empty filter will return everything. Pretty logical.
Btw, it's the same as in Route::setSchemes
.
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.
What I also find bad is that you can get all messages for all domains, but not for all locales.
I'd propose to simply remove the domains parameter. The logic that it implements can simply be done by the user. And the method should only have a single responsibility, and that is not filtering domains.
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.
@Tobion Frankly, don't see anything bad of allowing to filter messages at the fetch method. It looks natural for me. Confident, that other developers will find it usefull.
Regarding "null
vs. array()
", I'm like 45/55. Your argument
to get every domain if you pass an empty list.
seems reasonable for me. That's how most UI filters works "empty filter list --> all records". That's why, have implemented it this way first time. But, really don't see a big deal to use null
for all messages. There's only matter of integrity and consistency, and IMHO array()
fits more those requirements.
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.
Yes it might be useful, but everything is useful for someone. The point is,
- it violates single responsibility
- is really simply to do in user-land, just `$messages['mydomain']
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.
@Tobion, you are definitely right. It won't be hard to pick proper domains by array's keys in afterwords. I've updated the method, the test and documentation as well.
Thank you.
👍 thanks @Grygir (although I have no vote permission) |
* | ||
* @param string|null $locale Locale of translations, by default is current locale | ||
* | ||
* @return array |
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.
Missing description that it returns array[array]
indexed by catalog.
Apart from the phpdoc above, 👍 |
@Tobion, thank you. Done. |
public function testGetMessages($resources, $locale, $expected) | ||
{ | ||
$locales = array_keys($resources); | ||
$_locale = !is_null($locale) ? $locale : reset($locales); |
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.
Why is this calculated instead of setting the value explicitly in the data provider?
Thank you @Grygir. |
…(Grygir) This PR was merged into the 2.6-dev branch. Discussion ---------- [Translation] added method to expose collected message | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | #2435 | License | MIT | Doc PR | symfony/symfony-docs#3386 Commits ------- ef5d7c5 [Translation] added method to expose collected messages
…(Grygir) This PR was merged into the master branch. Discussion ---------- [Translation] added method to expose collected message | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#9859) | Applies to | all (or 2.4+) | Fixed tickets | Commits ------- f701f73 [Translation] added method to expose collected message