From 85e61568daf4d6a12865acb2aea73a4778754a2c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 24 May 2014 12:52:09 +0100 Subject: [PATCH] Try harder to find a name in the right language --- app/helpers/browse_helper.rb | 10 ++++++++-- test/helpers/browse_helper_test.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 2b9cb6f99..bfc7db80b 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -13,8 +13,14 @@ module BrowseHelper # don't look at object tags if redacted, so as to avoid giving # away redacted version tag information. unless object.redacted? - if object.tags.include? "name:#{I18n.locale}" - name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags["name:#{I18n.locale}"].to_s ), :id => content_tag(:bdi, name) + locale = I18n.locale.to_s + + while locale =~ /-[^-]+/ and not object.tags.include? "name:#{I18n.locale}" + locale = locale.sub(/-[^-]+/, "") + end + + if object.tags.include? "name:#{locale}" + name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags["name:#{locale}"].to_s ), :id => content_tag(:bdi, name) elsif object.tags.include? 'name' name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags['name'].to_s ), :id => content_tag(:bdi, name) end diff --git a/test/helpers/browse_helper_test.rb b/test/helpers/browse_helper_test.rb index 38d8c2dff..830674940 100644 --- a/test/helpers/browse_helper_test.rb +++ b/test/helpers/browse_helper_test.rb @@ -29,6 +29,15 @@ class BrowseHelperTest < ActionView::TestCase assert_equal "проверки узла (18, v2)", printable_name(nodes(:node_with_name_current_version), true) assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true) + I18n.locale = "ru-RU" + + assert_equal "17", printable_name(current_nodes(:redacted_node)) + assert_equal "проверки узла (18)", printable_name(current_nodes(:node_with_name)) + assert_equal "проверки узла (18)", printable_name(nodes(:node_with_name_current_version)) + assert_equal "18", printable_name(nodes(:node_with_name_redacted_version)) + assert_equal "проверки узла (18, v2)", printable_name(nodes(:node_with_name_current_version), true) + assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true) + I18n.locale = "de" assert_equal "17", printable_name(current_nodes(:redacted_node)) -- 2.39.5