-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Translate some locales in order to match locales available from bower dependencies #4878
Conversation
a6584fb
to
698cb91
Compare
{% 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') %} |
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.
Can we move this stuff to a twig function to reduce the code inside the template?
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.
with tests, preferrably
111f66e
to
2fa76a7
Compare
* | ||
* @return null|string | ||
*/ | ||
public function getCanonicalizedLocaleForMoment(array $context) |
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 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 |
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 remove this
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.
You mean the whole docblock @greg0ire?
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.
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 |
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 use backticks here?
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.
Beacuse this is a reference to a version constraint declared in bower.json
at sonata-project/core-bundle
.
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 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
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.
This is not for a tool, I use backticks just to make explicit that this constraint is used here as a snippet.
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.
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 |
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 remove this
@greg0ire, how I should execute |
@phansys this sounds overkill, but if we were to accept that, I think it would mean a separate Travis job just for that. |
Your concerns are about performance? I was thinking to use the |
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)) { |
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.
This poses the same problem for nl-nl
. Moment only has nl.js
, but Symfony's request locale is nl-nl
.
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.
Can you do something about it @phansys ?
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.
3c9f241
to
3b55476
Compare
Can you please check FlintCI? |
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.
👍🏻
@OskarStark, FlintCI suggested changes are not related to this PR. Would I apply them? |
Strange, could you rebase? |
{ | ||
$context = $this->mockExtensionContext($original); | ||
|
||
$this->assertSame($this->twigExtension->getCanonicalizedLocaleForSelect2($context), $canonicalized); |
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 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
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.
Same for the other method
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.
Thank you @OskarStark, done.
138040c
to
dd1c609
Compare
Rebased. |
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.
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 |
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.
do we really need this comment?
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 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) |
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 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]), |
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 use the new, namespaced version. See https://github.com/rectorphp/rector/blob/master/src/config/level/twig/underscore-to-namespace.yml
*/ | ||
public function testCanonicalizedLocaleForMoment($original, $expected) | ||
{ | ||
$context = $this->mockExtensionContext($original); |
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 get rid of this one time variable
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?
|
be99547
to
483b0fa
Compare
Rebased and squashed @greg0ire. |
483b0fa
to
4dc0c39
Compare
@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. |
@greg0ire please give a final review, thank you! |
4dc0c39
to
83484cd
Compare
Thank you @OskarStark. |
I am targeting this branch, because there are some locales from bower dependencies which are not found under the current implementation.
Changelog
TODO
Closes #3642.