diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-18 10:29:18 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-18 10:38:53 +0200 |
commit | 07313018054e3237ee9041001d3de76ca3ba756c (patch) | |
tree | aabd7f3cad6d715572ef38bf64dfe4af9934d708 | |
parent | f69b54682fc1770a73c528032b1a86f3e7d547a1 (diff) | |
download | gitlab-ce-bvl-fix-locale-path.tar.gz |
Build the locale path with an `_` instead of a `-`bvl-fix-locale-path
The locale code is turned into an asset path with an underscore
instead of a dash.
The language codes are transformed by `I18n.locale` into a code with a
dash. But the resources for translating are always stored in a path
using a `_` separating the language and the region code.
-rw-r--r-- | app/helpers/application_helper.rb | 6 | ||||
-rw-r--r-- | app/views/layouts/_head.html.haml | 2 | ||||
-rw-r--r-- | changelogs/unreleased/bvl-fix-locale-path.yml | 5 | ||||
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 8 |
4 files changed, 20 insertions, 1 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d02d5de5c3..4b65499e712 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -309,4 +309,10 @@ module ApplicationHelper def show_new_repo? cookies["new_repo"] == "true" && body_data_page != 'projects:show' end + + def locale_path + locale_path = I18n.locale.to_s || I18n.default_locale.to_s + + asset_path("locale/#{locale_path.tr('-', '_')}/app.js") + end end diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index f1b32274664..1597621fa78 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -37,7 +37,7 @@ - if content_for?(:library_javascripts) = yield :library_javascripts - = javascript_include_tag asset_path("locale/#{I18n.locale.to_s || I18n.default_locale.to_s}/app.js") unless I18n.locale == :en + = javascript_include_tag locale_path unless I18n.locale == :en = webpack_bundle_tag "webpack_runtime" = webpack_bundle_tag "common" = webpack_bundle_tag "main" diff --git a/changelogs/unreleased/bvl-fix-locale-path.yml b/changelogs/unreleased/bvl-fix-locale-path.yml new file mode 100644 index 00000000000..97e0e000e3c --- /dev/null +++ b/changelogs/unreleased/bvl-fix-locale-path.yml @@ -0,0 +1,5 @@ +--- +title: Correctly render asset path for locales with a region +merge_request: 14924 +author: +type: fixed diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 87ae1fa5660..66785cf32da 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -309,4 +309,12 @@ describe ApplicationHelper do end end end + + describe '#locale_path' do + it 'returns the locale path with an `_`' do + Gitlab::I18n.locale = 'pt-BR' + + expect(helper.locale_path).to include('assets/locale/pt_BR/app') + end + end end |