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

Dropdown to change locale #102

Closed
wants to merge 25 commits into from
Closed

Dropdown to change locale #102

wants to merge 25 commits into from

Conversation

JulienItard
Copy link
Contributor

see #83

Someone should add comments in routing.yml because my english it not good enough :)

capture du 2015-07-15 19 52 19

@JulienItard JulienItard changed the title Dropdown to change locale #83 Dropdown to change locale Jul 15, 2015
requirements:
_locale: en|fr|de|es|cs|ru|uk|
defaults:
_locale: en
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea

@weaverryan
Copy link
Member

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

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

Copy link
Contributor

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?

Copy link
Member

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)

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@javiereguiluz
Copy link
Member

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

@JulienItard
Copy link
Contributor Author

@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

@javiereguiluz
Copy link
Member

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

@stof
Copy link
Member

stof commented Jul 16, 2015

please revert the permission changes. Templates and config files have no reason to be executable

@JulienItard
Copy link
Contributor Author

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

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?

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 !

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javiereguiluz
Copy link
Member

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:

before

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:

after-1

It would be nice too if the current language is displayed in bold letters in the language list:

after-2

Lastly, if you don't like the fa-language icon, another common alternative is to use fa-globe, which FontAwesome also relates to "translation":

after-3

<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>
Copy link
Contributor

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 "Русский"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@bocharsky-bw
Copy link
Contributor

I vote for fa-language icon 👍

@JulienItard
Copy link
Contributor Author

I vote for fa-globe :)

@JulienItard
Copy link
Contributor Author

Up

@bocharsky-bw
Copy link
Contributor

Yeah, it's a bit overhead. What about to add Twig function to return locale_code => locale_name array of all supported locales?

@javiereguiluz
Copy link
Member

Yes, it would be better to create a Twig global variable from the locales parameter and use something like: for locale in locales|split('|')

@voronkovich
Copy link
Contributor

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.

@javiereguiluz
Copy link
Member

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

@bocharsky-bw
Copy link
Contributor

What about locale human readable names? Maybe somethink like:

twig:
    globals:
        languages:
            en: English
            ru: Russian
            # ... other

@voronkovich
Copy link
Contributor

@bocharsky-bw, I agree with you. In the template we will need languages names, not only codes.

@javiereguiluz
Copy link
Member

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

@voronkovich
Copy link
Contributor

@bocharsky-bw
Copy link
Contributor

Yep, Intl component could help us, but I think we need locales not countries

@JulienItard
Copy link
Contributor Author

Good ideas, i'll do it tomorrow.

@JulienItard
Copy link
Contributor Author

What do you think about it ?

@bocharsky-bw
Copy link
Contributor

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?

@JulienItard
Copy link
Contributor Author

Better ?

@bocharsky-bw
Copy link
Contributor

I like it more 👍

$array = explode('|', $this->container->getParameter('locales'));

foreach ($array as $locale) {
$locales[] = ['code' => $locale, 'name' => Intl::getLocaleBundle()->getLocaleName($locale, $locale)];
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@javiereguiluz
Copy link
Member

@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 :)

@bocharsky-bw
Copy link
Contributor

@JulienItard Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants