Skip to content
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

Translate some locales in order to match locales available from bower dependencies #4878

Conversation

phansys
Copy link
Member

@phansys phansys commented Jan 4, 2018

I am targeting this branch, because there are some locales from bower dependencies which are not found under the current implementation.

Changelog

### Fixed
- Not found issues for some locales which are not present in frontend dependencies like `moment` or `select2`

image

TODO

  • Add tests.

Closes #3642.

@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch 2 times, most recently from a6584fb to 698cb91 Compare January 4, 2018 02:12
{% if locale[:2] != 'en' %}
<script src="{{ asset('bundles/sonatacore/vendor/select2/select2_locale_' ~ locale|replace({'_':'-'}) ~ '.js') }}"></script>
{# localize select2 #}
{% if sonata_admin.adminPool.getOption('use_select2') %}
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this stuff to a twig function to reduce the code inside the template?

Copy link
Contributor

Choose a reason for hiding this comment

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

with tests, preferrably

@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch from 111f66e to 2fa76a7 Compare January 4, 2018 15:02
*
* @return null|string
*/
public function getCanonicalizedLocaleForMoment(array $context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be final

* Returns a canonicalized locale for "moment" NPM library,
* or `null` if the locale's language is "en", which doesn't require localization.
*
* @param array $context
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean the whole docblock @greg0ire?

Copy link
Contributor

Choose a reason for hiding this comment

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

no, just this line, it's tautologic, whereas the rest is interesting

return null;
}

// `moment: ^2.8` only ships "es" and "es-do" locales for "es" language
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use backticks here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Beacuse this is a reference to a version constraint declared in bower.json at sonata-project/core-bundle.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean why use this over quotes, etc... markdown is not recognized here, or is it some other markup? For what tool are you using this markup

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not for a tool, I use backticks just to make explicit that this constraint is used here as a snippet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, why not

* Returns a canonicalized locale for "select2" NPM library,
* or `null` if the locale's language is "en", which doesn't require localization.
*
* @param array $context
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this

@phansys
Copy link
Member Author

phansys commented Jan 4, 2018

@greg0ire, how I should execute bower install in the test suite in order to check for the available locales?
I was thinking to iterate over the resulting files to make sure we are not out of date with the shipped locales for these libraries.
Should I use different environments with distinct command flags for lowest / highest version resolutions?

@greg0ire
Copy link
Contributor

greg0ire commented Jan 4, 2018

@phansys this sounds overkill, but if we were to accept that, I think it would mean a separate Travis job just for that.

@phansys
Copy link
Member Author

phansys commented Jan 4, 2018

Your concerns are about performance? I was thinking to use the symfony/finder, which is really fast.

@greg0ire
Copy link
Contributor

greg0ire commented Jan 4, 2018

My concerns are about maintenance, but maybe you can try it anyway and I will be convinced :P

}

// `moment: ^2.8` only ships "es" and "es-do" locales for "es" language
if ('es' === $lang && !in_array($locale, ['es', 'es-do'], true)) {

Choose a reason for hiding this comment

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

This poses the same problem for nl-nl. Moment only has nl.js, but Symfony's request locale is nl-nl.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do something about it @phansys ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch from 3c9f241 to 3b55476 Compare January 16, 2018 16:14
@OskarStark
Copy link
Member

Can you please check FlintCI?

Copy link
Member

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

👍🏻

@phansys
Copy link
Member Author

phansys commented Jan 16, 2018

@OskarStark, FlintCI suggested changes are not related to this PR. Would I apply them?

@OskarStark
Copy link
Member

Strange, could you rebase?

{
$context = $this->mockExtensionContext($original);

$this->assertSame($this->twigExtension->getCanonicalizedLocaleForSelect2($context), $canonicalized);
Copy link
Member

Choose a reason for hiding this comment

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

Please rename canonicalized to expected and use it as the first argument, your code result should be the second argument.

Also switch the signature parameters in line 2353 please

Copy link
Member

Choose a reason for hiding this comment

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

Same for the other method

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you @OskarStark, done.

@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch from 138040c to dd1c609 Compare January 16, 2018 18:30
@phansys
Copy link
Member Author

phansys commented Jan 16, 2018

Rebased.

Copy link
Member

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Afterwards we can merge this PR

$locale = 'es';
}

// @todo: there are more locales which are not supported by moment and they need to be translated/normalized/canonicalized here
Copy link
Member

Choose a reason for hiding this comment

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

do we really need this comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think yes @OskarStark, since this method isn't getting rid of them (see #4878 (review) by instance). I think these matches should be added by users which know the right locale fallback in each case.

/**
* @dataProvider select2LocalesProvider
*/
public function testCanonicalizedLocaleForSelect2($original, $expected)
Copy link
Member

Choose a reason for hiding this comment

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

please use $expected as the first argument, like in the assertations.

Same for the other method

public function getFunctions()
{
return [
new \Twig_SimpleFunction('canonicalize_locale_for_moment', [$this, 'getCanonicalizedLocaleForMoment'], ['needs_context' => true]),
Copy link
Contributor

Choose a reason for hiding this comment

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

*/
public function testCanonicalizedLocaleForMoment($original, $expected)
{
$context = $this->mockExtensionContext($original);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please get rid of this one time variable

OskarStark
OskarStark previously approved these changes Jan 17, 2018
greg0ire
greg0ire previously approved these changes Jan 17, 2018
@greg0ire
Copy link
Contributor

Please kindly squash your commits together. If you don't, we'll try to remember to do it for you but it's best if you save us this trouble.

How to do that?

  1. git rebase -i origin/3.x, assuming origin is a git remote that points to this repository, and not your fork. If you're not sure what your remotes are, run git remote -vvv, there should be your fork and the holy/reference/base/origin/whatever-you-call-it repository.
  2. A window will show up with many lines, replace pick with fixup on every line but the first one
  3. Close your editor, git should do its magic, and you should end up with one commit
  4. Use git push --force to overwrite what you already pushed. Don't forget the --force option otherwise git will try to merge both things together.

@greg0ire greg0ire requested a review from core23 January 17, 2018 13:04
@phansys phansys dismissed stale reviews from greg0ire and OskarStark via 483b0fa January 17, 2018 13:06
@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch from be99547 to 483b0fa Compare January 17, 2018 13:06
@phansys
Copy link
Member Author

phansys commented Jan 17, 2018

Rebased and squashed @greg0ire.

@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch from 483b0fa to 4dc0c39 Compare January 17, 2018 13:21
@phansys
Copy link
Member Author

phansys commented Jan 25, 2018

@core23, @OskarStark; is there something preventing this PR to be merged. Please let me know if there is something on my side that could be done.

OskarStark
OskarStark previously approved these changes Jan 25, 2018
@OskarStark
Copy link
Member

@greg0ire please give a final review, thank you!

core23
core23 previously approved these changes Jan 25, 2018
@phansys phansys dismissed stale reviews from core23 and OskarStark via 83484cd January 25, 2018 20:16
@phansys phansys force-pushed the handling_locales_from_bower_dependencies branch from 4dc0c39 to 83484cd Compare January 25, 2018 20:16
@OskarStark OskarStark merged commit 33ff7c4 into sonata-project:3.x Jan 28, 2018
@phansys
Copy link
Member Author

phansys commented Jan 30, 2018

Thank you @OskarStark.

@phansys phansys deleted the handling_locales_from_bower_dependencies branch January 30, 2018 17:48
@phansys phansys mentioned this pull request Jul 27, 2019
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants