diff --git a/.travis.yml b/.travis.yml index dc5c459d..cd2afcb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,16 @@ +sudo: false language: ruby +# Limit ruby versions to currently supported versions to avoid a big build matrix rvm: - - 1.9.3 - - 2.0.0 + - 2.2 + - 2.3.0 +# Update bundler on travis, since current one is broken, see https://github.com/rubygems/rubygems/issues/1419 +before_install: + - gem install bundler # Load database schema before rake -before_script: bundle exec rake db:schema:load \ No newline at end of file +before_script: bundle exec rake db:schema:load +# Test on all supported rails versions +gemfile: + - gemfiles/activeadmin_master.gemfile + - gemfiles/rails4_1.gemfile + - gemfiles/rails4_2.gemfile diff --git a/Appraisals b/Appraisals new file mode 100644 index 00000000..5ff3e2fd --- /dev/null +++ b/Appraisals @@ -0,0 +1,15 @@ +appraise 'rails4_1' do + gem 'rails', '~> 4.1.12' + gem 'globalize', '~> 4.0.3' +end + +appraise 'rails4_2' do + gem 'rails', '~> 4.2.3' + gem 'globalize', '~> 5.0.0' +end + +# Run tests on latest github version of ActiveAdmin +appraise 'activeadmin_master' do + gem 'rails', '~> 4.2.0' + gem 'activeadmin', github: 'activeadmin/activeadmin' +end diff --git a/Gemfile b/Gemfile index a7b4c3ed..aaa1189b 100644 --- a/Gemfile +++ b/Gemfile @@ -14,8 +14,7 @@ gemspec # gem 'debugger' # Gems used by the dummy application -gem 'rails', '~> 4.0.0' -gem 'sass-rails', '~> 4.0.2' +gem 'sass-rails' gem 'coffee-rails' # See https://github.com/sstephenson/execjs#readme for more supported runtimes @@ -25,21 +24,21 @@ gem 'uglifier' # jquery-rails is gem 'jquery-rails' -# Fetch activeadmin from github until is released -gem 'devise' +# ActiveAdmin requires devise < 4.0 +gem 'devise', '~> 3.2' group :test do gem 'sqlite3', '~> 1.3.5' gem 'rspec-rails', '~> 2.14.0' gem 'factory_girl_rails', '~> 4.2.1' gem 'database_cleaner', '~> 1.0.1' - gem 'guard-rspec', require: false gem 'spring', require: false gem 'spring-commands-rspec', require: false gem 'capybara', '~> 2.1.0' gem 'capybara-screenshot' gem 'poltergeist' gem 'fuubar' + gem 'appraisal' # Useful to debug tests gem 'awesome_print' gem 'pry' diff --git a/Guardfile b/Guardfile deleted file mode 100644 index 7796ebd3..00000000 --- a/Guardfile +++ /dev/null @@ -1,16 +0,0 @@ -# A sample Guardfile -# More info at https://github.com/guard/guard#readme - -guard :rspec, cmd: 'spring rspec -f Fuubar' do - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } - - # Rails example - watch(%r{^dummy/app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } - watch(%r{^dummy/app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } - watch(%r{^dummy/app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } - watch(%r{^spec/support/(.+)\.rb$}) { "spec" } - -end - diff --git a/README.md b/README.md index c66845b6..a16eabdf 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,15 @@ active_admin_translates :title, :description do validates_presence_of :title end ``` -## Editor configuration +## In your Active Admin resource definition + +**Important note:** I'm working on a fix for #4 because after AA deprecated and then removed [#form_buffers](https://github.com/activeadmin/activeadmin/pull/3486) the +syntax shown below for form declaration doesn't work as is. See comments in code and [discussion](#4) to fix it until I found a solution. ```ruby # For usage with strong parameters you'll need to permit them -permit_params translations_attributes: [:id, :locale, :title, :content, :_destroy] +permit_params translations_attributes: [:id, :locale, :title, :description, :_destroy] index do # textual translation status @@ -38,17 +41,63 @@ index do # or with flag icons translation_status_flags # ... - default_actions + actions end +# This was the original syntax proposed in this gem, however currently it doesn't work form do |f| # ... f.translated_inputs "Translated fields", switch_locale: false do |t| t.input :title - t.input :content + t.input :description end # ... end + +# Instead you have to nest the block inside an #inputs block and the title +# should be passed to the inputs method +form do |f| + # ... + f.inputs "Translated fields" do + f.translated_inputs 'ignored title', switch_locale: false do |t| + t.input :title + t.input :description + end + end + # ... +end + +# You can also set locales to show in tabs +# For example we want to show English translation fields without tab, and want to show other languages within tabs +form do |f| + # ... + f.inputs do + Globalize.with_locale(:en) do + f.input :title + end + end + f.inputs "Translated fields" do + f.translated_inputs 'ignored title', switch_locale: false, available_locales: (I18n.available_locales - [:en]) do |t| + t.input :title + t.input :description + end + end + # ... +end + +# You can also set default language tab +# For example we want to make Bengali translation tab as default +form do |f| + # ... + f.inputs "Translated fields" do + f.translated_inputs 'ignored title', switch_locale: false, default_locale: :bn do |t| + t.input :title + t.input :description + end + end + # ... +end + ``` If `switch_locale` is set, each tab will be rendered switching locale. diff --git a/activeadmin-globalize.gemspec b/activeadmin-globalize.gemspec index c43cd54f..22867161 100644 --- a/activeadmin-globalize.gemspec +++ b/activeadmin-globalize.gemspec @@ -16,7 +16,8 @@ Gem::Specification.new do |s| s.files = Dir['{app,config,db,lib}/**/*'] + %w(MIT-LICENSE README.md) s.add_dependency 'activeadmin', '~> 1.0.0.pre' - s.add_dependency 'globalize', '~> 4.0' + # Try to support rails from 3.2 up to 4.2.x + s.add_dependency 'globalize', '>= 3.1.0', '< 6.0' # development dependencies s.add_development_dependency 'bundler', '>= 1.6.1' diff --git a/app/assets/images/active_admin/flags.png b/app/assets/images/active_admin/flags.png index e3bfc512..f5449832 100644 Binary files a/app/assets/images/active_admin/flags.png and b/app/assets/images/active_admin/flags.png differ diff --git a/app/assets/images/active_admin/transparent.gif b/app/assets/images/active_admin/transparent.gif deleted file mode 100644 index f191b280..00000000 Binary files a/app/assets/images/active_admin/transparent.gif and /dev/null differ diff --git a/app/assets/javascripts/active_admin/active_admin_globalize.js.coffee b/app/assets/javascripts/active_admin/active_admin_globalize.js.coffee index 31704db3..a4cc79ee 100644 --- a/app/assets/javascripts/active_admin/active_admin_globalize.js.coffee +++ b/app/assets/javascripts/active_admin/active_admin_globalize.js.coffee @@ -148,7 +148,8 @@ $ -> $td = $(this).closest('td') $('.field-translation', $td).hide() $(".locale-#{$locale}", $td).show() + $(this).parent().children('a.ui-translation-trigger').removeClass('active') + $(this).addClass('active') e.preventDefault() translations() - diff --git a/app/assets/stylesheets/active_admin/active_admin_globalize.css.sass b/app/assets/stylesheets/active_admin/active_admin_globalize.sass similarity index 100% rename from app/assets/stylesheets/active_admin/active_admin_globalize.css.sass rename to app/assets/stylesheets/active_admin/active_admin_globalize.sass diff --git a/app/assets/stylesheets/active_admin/active_admin_globalize_flags.css.sass b/app/assets/stylesheets/active_admin/active_admin_globalize_flags.sass similarity index 86% rename from app/assets/stylesheets/active_admin/active_admin_globalize_flags.css.sass rename to app/assets/stylesheets/active_admin/active_admin_globalize_flags.sass index 9ec60102..49126eba 100644 --- a/app/assets/stylesheets/active_admin/active_admin_globalize_flags.css.sass +++ b/app/assets/stylesheets/active_admin/active_admin_globalize_flags.sass @@ -3,6 +3,7 @@ // Override flag positions in your stylesheet if you want to change default flags .flag + display: inline-block width: 16px height: 11px vertical-align: middle @@ -33,10 +34,18 @@ background-position: -32px -22px &.flag-en // originally flag-us background-position: -48px -22px + &.flag-he // originally flag-il + background-position: 0 -33px // Used to distantiate inline locale selector span.inline-locale-selector margin-right: 10px + > .ui-translation-trigger + opacity: .4 + &.empty + filter: grayscale(100%) + &.active + opacity: 1 .field-translation.hidden display: none @@ -53,4 +62,4 @@ div.field-translation // prevent tr height flickering span.field-translation.empty - vertical-align: bottom \ No newline at end of file + vertical-align: bottom diff --git a/config/locales/ar.yml b/config/locales/ar.yml new file mode 100644 index 00000000..c55df508 --- /dev/null +++ b/config/locales/ar.yml @@ -0,0 +1,16 @@ +ar: + active_admin: + globalize: + translations: "ترجمة" + language: + de: "ألماني" + en: "الإنجليزية" + es: "الأسبانية" + fr: "اللغة الفرنسية" + hu: "الهنغارية" + it: "الإيطالي" + pt-BR: "البرتغالية" + pt-PT: "البرتغالية (البرتغال)" + tr: "اللغة التركية" + he: "العبرية" + diff --git a/config/locales/de.yml b/config/locales/de.yml index 386e40b0..60385c56 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -12,4 +12,6 @@ de: pt-BR: "Portugiesisch" pt-PT: "Portugiesisch (Portugal)" tr: "Türkisch" + he: "Hebräisch" + ar: "Arabisch" diff --git a/config/locales/en.yml b/config/locales/en.yml index d8c4b741..44ebb8c6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,4 +12,6 @@ en: pt-BR: "Portuguese" pt-PT: "Portuguese (Portugal)" tr: "Turkish" + he: "Hebrew" + ar: "Arabic" diff --git a/config/locales/es.yml b/config/locales/es.yml new file mode 100644 index 00000000..ed5020d2 --- /dev/null +++ b/config/locales/es.yml @@ -0,0 +1,17 @@ +es: + active_admin: + globalize: + translations: "Traducciones" + language: + de: "Alemán" + en: "Inglés" + es: "Español" + fr: "Francés" + hu: "Húngaro" + it: "Italiano" + pt-BR: "Portugués" + pt-PT: "Portugués (Portugal)" + tr: "Turco" + he: "Hebreo" + ar: "Arábica" + diff --git a/config/locales/he.yml b/config/locales/he.yml new file mode 100644 index 00000000..6543613c --- /dev/null +++ b/config/locales/he.yml @@ -0,0 +1,17 @@ +he: + active_admin: + globalize: + translations: "תרגומים" + language: + de: "גרמנית" + en: "אנגלית" + es: "ספרדית" + fr: "צרפתית" + hu: "הונגרית" + it: "איטלקית" + pt-BR: "פורטוגזית" + pt-PT: "פורטוגזית (פורטוגל)" + tr: "טורקית" + he: "עברית" + ar: "ערבית" + diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 5440c653..802ab8cc 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -12,4 +12,6 @@ hu: pt-BR: "Portuguese" pt-PT: "Portuguese (Portugal)" tr: "Török" + he: "Héber" + ar: "Arab" diff --git a/config/locales/it.yml b/config/locales/it.yml index a3b1e08c..e7668bdf 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -12,4 +12,6 @@ it: pt-BR: "Portoghese" pt-PT: "Portoghese (Portogallo)" tr: "Turco" + he: "Ebraico" + ar: "Arabo" diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index f5292a03..9abe75e7 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -12,4 +12,6 @@ pt-BR: pt-BR: "Português" pt-PT: "Português (Portugal)" tr: "Turco" + he: "Hebraico" + ar: "Árabe" diff --git a/config/locales/pt-PT.yml b/config/locales/pt-PT.yml index 6249ab44..173fbad6 100644 --- a/config/locales/pt-PT.yml +++ b/config/locales/pt-PT.yml @@ -12,4 +12,6 @@ pt-PT: pt-BR: "Português" pt-PT: "Português (Portugal)" tr: "Turco" + he: "Hebraico" + ar: "Árabe" diff --git a/gemfiles/activeadmin_master.gemfile b/gemfiles/activeadmin_master.gemfile new file mode 100644 index 00000000..f998d30f --- /dev/null +++ b/gemfiles/activeadmin_master.gemfile @@ -0,0 +1,30 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sass-rails" +gem "coffee-rails" +gem "therubyracer", :platforms => :ruby +gem "uglifier" +gem "jquery-rails" +gem "devise", "~> 3.2" +gem "rails", "~> 4.2.0" +gem "activeadmin", :github => "activeadmin/activeadmin" + +group :test do + gem "sqlite3", "~> 1.3.5" + gem "rspec-rails", "~> 2.14.0" + gem "factory_girl_rails", "~> 4.2.1" + gem "database_cleaner", "~> 1.0.1" + gem "spring", :require => false + gem "spring-commands-rspec", :require => false + gem "capybara", "~> 2.1.0" + gem "capybara-screenshot" + gem "poltergeist" + gem "fuubar" + gem "appraisal" + gem "awesome_print" + gem "pry" +end + +gemspec :path => "../" diff --git a/gemfiles/rails4_1.gemfile b/gemfiles/rails4_1.gemfile new file mode 100644 index 00000000..9d023afa --- /dev/null +++ b/gemfiles/rails4_1.gemfile @@ -0,0 +1,30 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sass-rails" +gem "coffee-rails" +gem "therubyracer", :platforms => :ruby +gem "uglifier" +gem "jquery-rails" +gem "devise", "~> 3.2" +gem "rails", "~> 4.1.12" +gem "globalize", "~> 4.0.3" + +group :test do + gem "sqlite3", "~> 1.3.5" + gem "rspec-rails", "~> 2.14.0" + gem "factory_girl_rails", "~> 4.2.1" + gem "database_cleaner", "~> 1.0.1" + gem "spring", :require => false + gem "spring-commands-rspec", :require => false + gem "capybara", "~> 2.1.0" + gem "capybara-screenshot" + gem "poltergeist" + gem "fuubar" + gem "appraisal" + gem "awesome_print" + gem "pry" +end + +gemspec :path => "../" diff --git a/gemfiles/rails4_2.gemfile b/gemfiles/rails4_2.gemfile new file mode 100644 index 00000000..95eae508 --- /dev/null +++ b/gemfiles/rails4_2.gemfile @@ -0,0 +1,30 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "sass-rails" +gem "coffee-rails" +gem "therubyracer", :platforms => :ruby +gem "uglifier" +gem "jquery-rails" +gem "devise", "~> 3.2" +gem "rails", "~> 4.2.3" +gem "globalize", "~> 5.0.0" + +group :test do + gem "sqlite3", "~> 1.3.5" + gem "rspec-rails", "~> 2.14.0" + gem "factory_girl_rails", "~> 4.2.1" + gem "database_cleaner", "~> 1.0.1" + gem "spring", :require => false + gem "spring-commands-rspec", :require => false + gem "capybara", "~> 2.1.0" + gem "capybara-screenshot" + gem "poltergeist" + gem "fuubar" + gem "appraisal" + gem "awesome_print" + gem "pry" +end + +gemspec :path => "../" diff --git a/lib/active_admin/globalize/attributes_table_extension.rb b/lib/active_admin/globalize/attributes_table_extension.rb index a294449a..385c3e7e 100644 --- a/lib/active_admin/globalize/attributes_table_extension.rb +++ b/lib/active_admin/globalize/attributes_table_extension.rb @@ -53,7 +53,7 @@ def translated_row(*args, &block) if options[:inline] ''.html_safe.tap do |value| # Add selectors for inline locale - value << inline_locale_selectors + value << inline_locale_selectors(field, options[:locale], &block) # Build translations spans value << field_translations(field, :span, options[:locale], &block) end @@ -61,7 +61,7 @@ def translated_row(*args, &block) content_tag(:div, class: 'activeadmin-translations') do ''.html_safe.tap do |value| # Render selectors as in translation ui - value << block_locale_selectors + value << block_locale_selectors(field, options[:locale], &block) # Build translations divs for actual translations value << field_translations(field, :div, options[:locale], &block) end @@ -82,20 +82,18 @@ def translatable?(field) # @param [String] field field name to render # @param [Symbol] tag tag to enclose field translation # @param [Symbol] initial_locale locale to set as not hidden - def field_translations(field, tag, initial_locale) + def field_translations(field, tag, initial_locale, &block) available_translations.map do |translation| # Classes for translation span only first element is visible css_classes = ['field-translation', "locale-#{translation.locale}"] # Initially only element for selected locale is visible css_classes.push 'hidden' unless translation.locale == initial_locale.to_sym # Build content for cell or div using translation locale and given block - content = I18n.with_locale(translation.locale) do - block_given? ? yield(translation) : translation.send(field) - end + content = field_translation_value(translation, field, &block) # return element if tag == :span # inline element # attach class to span if inline - css_classes.push(:empty) if content.blank? + css_classes.push('empty') if content.blank? content_tag(tag, content.presence || 'Empty', class: css_classes) else # block content @@ -107,13 +105,16 @@ def field_translations(field, tag, initial_locale) end.join(' ').html_safe end - def block_locale_selectors + def block_locale_selectors(field, initial_locale, &block) content_tag(:ul, class: 'available-locales locale-selector') do - available_translations.map(&:locale).map do |locale| - default = 'default' if locale == I18n.default_locale - content_tag(:li, class: 'translation-tab') do - I18n.with_locale(locale) do - content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href: ".locale-#{locale}", class: default) + available_translations.map do |translation| + css_classes = ['translation-tab'] + css_classes << 'active' if translation.locale == initial_locale.to_sym + css_classes << 'empty' unless content.presence + content_tag(:li, class: css_classes) do + I18n.with_locale(translation.locale) do + default = 'default' if translation.locale == initial_locale.to_sym + content_tag(:a, I18n.t(:"active_admin.globalize.language.#{translation.locale}"), href: ".locale-#{translation.locale}", class: default) end end end.join.html_safe @@ -121,11 +122,15 @@ def block_locale_selectors end # Return flag elements to show the given locale using javascript - def inline_locale_selectors + def inline_locale_selectors(field, initial_locale, &block) content_tag(:span, class: 'inline-locale-selector') do available_translations.map do |translation| + content = field_translation_value(translation, field, &block) + css_classes = ['ui-translation-trigger'] + css_classes << 'active' if translation.locale == initial_locale.to_sym + css_classes << 'empty' unless content.presence # Build a link to show the given translation - link_to(flag_icon(translation.locale), '#', class: 'ui-translation-trigger', data: {locale: translation.locale}) + link_to(flag_icon(translation.locale), '#', class: css_classes, data: {locale: translation.locale}) end.join(' ').html_safe end end @@ -134,6 +139,11 @@ def available_translations @record_translations ||= @collection.first.translations.order(:locale) end + def field_translation_value(translation, field) + I18n.with_locale(translation.locale) do + block_given? ? yield(translation) : translation.send(field) + end + end end end end diff --git a/lib/active_admin/globalize/form_builder_extension.rb b/lib/active_admin/globalize/form_builder_extension.rb index 0b11aedb..e68aaef2 100644 --- a/lib/active_admin/globalize/form_builder_extension.rb +++ b/lib/active_admin/globalize/form_builder_extension.rb @@ -5,12 +5,13 @@ module FormBuilderExtension def translated_inputs(name = "Translations", options = {}, &block) options.symbolize_keys! + available_locales = options.fetch(:available_locales, I18n.available_locales) switch_locale = options.fetch(:switch_locale, false) - auto_sort = options.fetch(:auto_sort, true) + default_locale = options.fetch(:default_locale, I18n.default_locale) template.content_tag(:div, class: "activeadmin-translations") do template.content_tag(:ul, class: "available-locales") do - (auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale| - default = 'default' if locale == I18n.default_locale + available_locales.map do |locale| + default = 'default' if locale == default_locale template.content_tag(:li) do I18n.with_locale(switch_locale ? locale : I18n.locale) do template.content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href:".locale-#{locale}", :class => default) @@ -18,7 +19,7 @@ def translated_inputs(name = "Translations", options = {}, &block) end end.join.html_safe end << - (auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale| + available_locales.map do |locale| translation = object.translations.find { |t| t.locale.to_s == locale.to_s } translation ||= object.translations.build(locale: locale) fields = proc do |form| @@ -42,4 +43,3 @@ module ClassMethods end end end - diff --git a/lib/active_admin/view_helpers/flag_helper.rb b/lib/active_admin/view_helpers/flag_helper.rb index c60c2997..853185f1 100644 --- a/lib/active_admin/view_helpers/flag_helper.rb +++ b/lib/active_admin/view_helpers/flag_helper.rb @@ -6,7 +6,7 @@ module FlagHelper # Return an image tag with background of given locale def flag_icon(locale) - image_tag('active_admin/transparent.gif', class: "flag flag-#{locale}") + content_tag :i, '', class: "flag flag-#{locale}", title: I18n.t("active_admin.globalize.language.#{locale}") end end diff --git a/spec/features/article_composing_spec.rb b/spec/features/article_composing_spec.rb index 0e93c3a7..a4296363 100644 --- a/spec/features/article_composing_spec.rb +++ b/spec/features/article_composing_spec.rb @@ -61,7 +61,16 @@ within first_table_row do page.should have_css 'th', text: 'TITLE' page.should have_css 'span.field-translation', text: article.title + + flag_link(:hu).find(:xpath, '..').should have_css '.empty:not(.active)' + flag_link(:it).find(:xpath, '..').should have_css ':not(.empty):not(.active)' + + flag_link(:hu).click # change shown translation + flag_link(:hu).find(:xpath, '..').should have_css '.empty.active' + flag_link(:it).click # change shown translation + flag_link(:it).find(:xpath, '..').should have_css ':not(.empty).active' + page.should have_css 'span.field-translation', text: article.translation_for(:it).title end @@ -101,4 +110,4 @@ end -end \ No newline at end of file +end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 2d905713..3e3c6b61 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -12,14 +12,22 @@ let(:article) { create(:localized_article) } subject { article } - it { should have(2).translations } + it { should have(3).translations } it 'should have italian translation' do I18n.with_locale :it do article.title.should == 'Italian title' + article.body.should == 'Italian Body' + end + end + + it 'should have hungarian translation' do + I18n.with_locale :hu do + article.title.should == 'Article title' + article.body.should == 'Hungarian Body' end end end -end \ No newline at end of file +end diff --git a/spec/support/capybara_activeadmin_helpers.rb b/spec/support/capybara_activeadmin_helpers.rb index 3f592f0d..06b77330 100644 --- a/spec/support/capybara_activeadmin_helpers.rb +++ b/spec/support/capybara_activeadmin_helpers.rb @@ -80,7 +80,7 @@ def flag_icon(locale = I18n.locale) # Return an a element used to trigger language switch using javascript def flag_link(locale = I18n.locale) # find the flag icon by class and go back to parent to get the link - find(:xpath, %Q{.//img[contains(@class, "flag-#{locale}")]/..}) + find(:xpath, %Q{.//i[contains(@class, "flag-#{locale}")]/..}) end # Link used to switch tabs for translations diff --git a/spec/support/factories/articles.rb b/spec/support/factories/articles.rb index 6066e21e..8046b715 100644 --- a/spec/support/factories/articles.rb +++ b/spec/support/factories/articles.rb @@ -9,6 +9,7 @@ after :create do |a| I18n.with_locale(:it) { a.update_attributes! title: 'Italian title', body: 'Italian Body' } + I18n.with_locale(:hu) { a.update_attributes! body: 'Hungarian Body' } end end