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
Dropdown to change locale #102
Conversation
requirements: | ||
_locale: en|fr|de|es|cs|ru|uk| | ||
defaults: | ||
_locale: en |
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 we should use _locale: "%locale%"
in order to use locale
parameter from parameters.yml
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.
good idea
@JulienItard I like the flags, but where are they from? Also, I think we should only add the flags that we're using from now (especially if we know the source, and can find other flags if we need them) |
@@ -7,6 +7,11 @@ | |||
app: | |||
resource: @AppBundle/Controller/ | |||
type: annotation | |||
prefix: /{_locale} | |||
requirements: | |||
_locale: en|fr|de|es|cs|ru|uk| |
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.
One too many |
at the end
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 we should move accepted locales to parameters.yml
too, for example:
# parameters.yml
parameters:
locales: en|fr|de|es|cs|ru|uk|
So we could easily refers to it in other routes in future.
What do you think?
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.
Actually, it should go into a parameters
key in config.yml
in that case (since it doesn't change on a machine-by-machine basis). I think that's a good idea (we'll add a comment explaining it)
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.
@weaverryan The last |
means that locale could be an empty string. We want to use routes without locale by default for en
lang
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.
Done.
@JulienItard thanks for this. I like it. My only concern are the flags. I think we should get rid of them. This is one of the classic usability problems, as explained here. Take for the example the Spanish language: it's official in 21 different countries, but we only show the flag for one specific country. |
@weaverryan I use these flags https://dribbble.com/shots/1211759-Free-195-Flat-Flags @javiereguiluz yes, but i use the country where the langage originally comes from |
@JulienItard I'm afraid that's not a good enough reason. Flags cannot be shown in a language selector because countries and languages have nothing to do. In you look around, you'll only see flags when a website lets you select a country, not a language. |
please revert the permission changes. Templates and config files have no reason to be executable |
Everything is ok now? |
<li><a href="{{ path('blog_index', {_locale:'ro'}) }}">Român</a></li> | ||
<li><a href="{{ path('blog_index', {_locale:'ru'}) }}">Pусский</a></li> | ||
<li><a href="{{ path('blog_index', {_locale:'uk'}) }}">Yкраїнська</a></li> | ||
<li><a href="{{ path('blog_index', {_locale:'cs'}) }}">česká republika</a></li> |
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 guess česká republika
means Czech Republic
(the country) instead of Czech
(the language). Is it Česko
more appropriate?
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.
Česky
would be the correct one.
Thanks for pointing out @javiereguiluz !
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.
Could you please add Português Brasileiro (pt_BR) to the dropdown?
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.
@javiereguiluz @TomasVotruba Done.
@davialexandre My bad. Done.
I've tested it and from a code point of view, everything looks correct to me. However, I'd like to suggest some design changes. This is the current design: The first issue I see is that the icon represents a flag, which has nothing to do with languages ;) The second issue, is that I think it's better to display the current language name. The last issue is that this selector is usually dispalyed at the rightmost part of the page. Something like this: It would be nice too if the current language is displayed in bold letters in the language list: Lastly, if you don't like the |
<li><a href="{{ path('blog_index', {_locale:'es'}) }}">Español</a></li> | ||
<li><a href="{{ path('blog_index', {_locale:'fr'}) }}">Français</a></li> | ||
<li><a href="{{ path('blog_index', {_locale:'ro'}) }}">Român</a></li> | ||
<li><a href="{{ path('blog_index', {_locale:'ru'}) }}">Pусский</a></li> |
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.
The first letter in this word is from English alphabet now. Could you replace (copy/paste) it with "Русский"?
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.
Done.
I vote for |
I vote for fa-globe :) |
Up |
Yeah, it's a bit overhead. What about to add |
Yes, it would be better to create a Twig global variable from the |
Parameters do not need to be flat strings, they can also contain array values: http://symfony.com/doc/current/components/dependency_injection/parameters.html#array-parameters. You don't need to use the "split" function. |
@voronkovich yes, but we want to define the locales in one single parameter and then, define the global Twig variable based on that parameter: parameters:
locales: en|fr|de|es|cs|ru|uk|ro|pt_BR
# ...
twig:
globals:
locales: %locales% |
What about locale human readable names? Maybe somethink like: twig:
globals:
languages:
en: English
ru: Russian
# ... other |
@bocharsky-bw, I agree with you. In the template we will need languages names, not only codes. |
I was hoping we can define just the locale codes and Symfony will do the magic of displaying the name of each language in its own language (English, Français, Español, etc.) |
@javiereguiluz, are you meaning this? http://symfony.com/doc/current/components/intl.html#country-names |
Yep, |
Good ideas, i'll do it tomorrow. |
What do you think about it ? |
I think locale menu relates to whole project, not only to Blog, so this method in BlogController a bit confused me. Maybe better to use custom Twig function in order to render locale menu? |
Better ? |
I like it more 👍 |
$array = explode('|', $this->container->getParameter('locales')); | ||
|
||
foreach ($array as $locale) { | ||
$locales[] = ['code' => $locale, 'name' => Intl::getLocaleBundle()->getLocaleName($locale, $locale)]; |
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.
We need to use the long array syntax because we still target PHP 5.3. Sorry.
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.
Done.
@JulienItard thanks a lot for implementing this feature, for your patience during the review process and for removing the flags even if you didn't want to do it at first :) |
@JulienItard Thanks a lot! |
see #83
Someone should add comments in routing.yml because my english it not good enough :)