Skip to content

Commit

Permalink
Translate some locales in order to match locales available from bower…
Browse files Browse the repository at this point in the history
… dependencies
  • Loading branch information
phansys committed Jan 4, 2018
1 parent 11c3ea6 commit a6584fb
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/Resources/views/standard_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,36 @@ file that was distributed with this source code.
{% endblock %}

{% set locale = app.request.locale %}
{# localize moment #}

{# omit default "en" locale #}
{% if locale[:2] != 'en' %}
{# localize moment #}
{% set localeForMoment = locale|lower|replace({'_':'-'}) %}
{# `moment: ^2.8` only ships "es" and "es-do" locales for "es" language #}
{% if localeForMoment[:2] == 'es' and localeForMoment not in ['es', 'es-do'] %}{% set localeForMoment = 'es' %}{% endif %}
{# @todo: there are more locales which are not supported by moment and they need to be translated/normalized/canonicalized here #}
<script src="{{ asset(
'bundles/sonatacore/vendor/moment/locale/' ~
locale|lower|replace({'_':'-'}) ~
localeForMoment ~
'.js'
) }}"></script>
{% endif %}

{# localize select2 #}
{% if sonata_admin.adminPool.getOption('use_select2') %}
{% if locale == 'pt' %}{% set locale = 'pt_PT' %}{% endif %}

{# omit default EN locale #}
{% 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') %}
{% set localeForSelect2 = locale %}
{% if locale == 'pt' %}
{# `select2: ^3.5` only ships "pt" locale as "pt-PT" #}
{% set localeForSelect2 = 'pt-PT' %}
{% elseif locale == 'ug' %}
{# `select2: ^3.5` only ships "ug" locale as "ug-CN" #}
{% set localeForSelect2 = 'ug-CN' %}
{% elseif locale == 'zh' %}
{# `select2: ^3.5` only ships "zh" locale as "zh-CN" and "zh-TW" #}
{% set localeForSelect2 = 'zh-CN' %}
{% elseif locale != 'zh-TW' %}
{% set localeForSelect2 = locale[:2] %}
{% endif %}
<script src="{{ asset('bundles/sonatacore/vendor/select2/select2_locale_' ~ localeForSelect2 ~ '.js') }}"></script>
{% endif %}
{% endif %}
{% endblock %}
Expand Down

0 comments on commit a6584fb

Please sign in to comment.