Commit 660411f45eb5c57839bc281540d7b36f62d1ef1a

Authored by Antonio Terceiro
1 parent ce7e0d21

ActionItem882: putting current language in HTML header

app/helpers/language_helper.rb
@@ -7,6 +7,10 @@ module LanguageHelper @@ -7,6 +7,10 @@ module LanguageHelper
7 language.downcase 7 language.downcase
8 end 8 end
9 9
  10 + def html_language
  11 + language.downcase.gsub('_', '-')
  12 + end
  13 +
10 alias :calendar_date_select_language :tinymce_language 14 alias :calendar_date_select_language :tinymce_language
11 15
12 def language_chooser(options = {}) 16 def language_chooser(options = {})
app/views/layouts/application.rhtml
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br"> 2 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= html_language %>" lang="<%= html_language %>">
3 <head> 3 <head>
4 <title> 4 <title>
5 <%= @environment.name() %> 5 <%= @environment.name() %>
test/integration/locale_setting_test.rb
@@ -64,6 +64,14 @@ class LocaleSettingTest &lt; ActionController::IntegrationTest @@ -64,6 +64,14 @@ class LocaleSettingTest &lt; ActionController::IntegrationTest
64 64
65 end 65 end
66 66
  67 + should 'put current language in HTML headers' do
  68 + get '/', :lang => 'pt_BR'
  69 + assert_tag :tag => 'html', :attributes => { 'xml:lang' => 'pt-br', 'lang' => 'pt-br' }
  70 +
  71 + get '/', :lang => 'en'
  72 + assert_tag :tag => 'html', :attributes => { 'xml:lang' => 'en', 'lang' => 'en' }
  73 + end
  74 +
67 protected 75 protected
68 76
69 def assert_locale(locale) 77 def assert_locale(locale)
test/unit/language_helper_test.rb
@@ -18,6 +18,11 @@ class LanguageHelperTest &lt; Test::Unit::TestCase @@ -18,6 +18,11 @@ class LanguageHelperTest &lt; Test::Unit::TestCase
18 assert_equal 'pt_br', tinymce_language 18 assert_equal 'pt_br', tinymce_language
19 end 19 end
20 20
  21 + should 'downcase and use dash for HTML language' do
  22 + self.expects(:language).returns('pt_BR')
  23 + assert_equal 'pt-br', html_language
  24 + end
  25 +
21 should 'generate language chooser correcly' do 26 should 'generate language chooser correcly' do
22 Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once 27 Noosfero.expects(:locales).returns({ 'en' => 'English', 'pt_BR' => 'Português Brasileiro', 'fr' => 'Français', 'it' => 'Italiano' }).at_least_once
23 28