Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Aug 27, 2014
Merged

[Translation] added method to expose collected message #9859

merged 1 commit into from
Aug 27, 2014

Conversation

Grygir
Copy link
Contributor

@Grygir 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

@jakzal
Copy link
Contributor

jakzal commented Dec 26, 2013

@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.

@Grygir
Copy link
Contributor Author

Grygir commented Dec 26, 2013

@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.

@fabpot
Copy link
Member

fabpot commented Dec 28, 2013

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

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.

@Grygir
Copy link
Contributor Author

Grygir commented Jan 8, 2014

@fabpot thanks, all commented issues are fixed.


$domains = array_flip($domains);
$messages = array();
for ($i = count($catalogues) - 1; $i >= 0; $i--) {

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

Copy link
Contributor Author

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.

@aitboudad
Copy link
Contributor

You should update the CHANGELOG file (in the component dir)

@Grygir
Copy link
Contributor Author

Grygir commented Jan 15, 2014

@aitboudad, do I understand correctly, this note should be in a section related to the coming version (2.5.0)?

@aitboudad
Copy link
Contributor

@Grygir
Copy link
Contributor Author

Grygir commented Jan 15, 2014

@aitboudad, done, thanks

@wouterj
Copy link
Member

wouterj commented Jul 24, 2014

@fabpot is there any change this can be merged?

@Grygir you have to rebase this PR, there are merge conflicts now.

@Grygir
Copy link
Contributor Author

Grygir commented Jul 24, 2014

@wouterj pull request is updated, thanks

@wouterj
Copy link
Member

wouterj commented Jul 24, 2014

👍 great!

*
* @return array
*/
public function exposeMessages(array $domains = array(), $locale = null)
Copy link
Member

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()?

@Grygir
Copy link
Contributor Author

Grygir commented Jul 24, 2014

@fabpot thank you, all comments are fixed (related symfony-docs pull request is updated as well)

@fabpot
Copy link
Member

fabpot commented Jul 24, 2014

👍

@wouterj
Copy link
Member

wouterj commented Jul 24, 2014

Great work, @fabpot, nice to see this one picked up that fast!

@sstok
Copy link
Contributor

sstok commented Jul 24, 2014

👍

*
* @return array
*/
public function getMessages(array $domains = null, $locale = null)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Tobion agree with you. That how I first time made. Then @fabpot asked to change. But I think it's not critical. Both variants are fine for me.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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,

  1. it violates single responsibility
  2. is really simply to do in user-land, just `$messages['mydomain']

Copy link
Contributor Author

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.

@wouterj
Copy link
Member

wouterj commented Jul 25, 2014

👍 thanks @Grygir (although I have no vote permission)

*
* @param string|null $locale Locale of translations, by default is current locale
*
* @return array
Copy link
Contributor

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.

@Tobion
Copy link
Contributor

Tobion commented Aug 16, 2014

Apart from the phpdoc above, 👍

@Grygir
Copy link
Contributor Author

Grygir commented Aug 18, 2014

@Tobion, thank you. Done.

public function testGetMessages($resources, $locale, $expected)
{
$locales = array_keys($resources);
$_locale = !is_null($locale) ? $locale : reset($locales);
Copy link
Contributor

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?

@fabpot
Copy link
Member

fabpot commented Aug 27, 2014

Thank you @Grygir.

@fabpot fabpot merged commit ef5d7c5 into symfony:master Aug 27, 2014
fabpot added a commit that referenced this pull request Aug 27, 2014
…(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
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Nov 4, 2014
…(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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants