From d0c249af2a2e630ac993eb23a691ef996613b55f Mon Sep 17 00:00:00 2001 From: Adrien Coquio Date: Sun, 3 Jun 2012 21:37:41 +0200 Subject: Added i18n support to models through globalize3. * Added Post translation * Added Category translation * Use friendly_id globalize with category * Added migrate_data option on migrations for translations * Use Refinery locale instead of I18n * Refactored duplicate locale_picker partial * Removed useless .all call * Use presence instead if / blank? * Added with_globalize scopes when loading posts of one category * Use Globalize when creating post factory * Fix failing specs by creating blog posts/categories using needed locale. --- app/views/refinery/blog/admin/categories/_category.html.erb | 12 ++++++++++-- app/views/refinery/blog/admin/categories/_form.html.erb | 3 +++ app/views/refinery/blog/admin/posts/_form.html.erb | 3 +++ app/views/refinery/blog/admin/posts/_post.html.erb | 11 ++++++++++- app/views/refinery/blog/admin/shared/_locale_picker.html.erb | 11 +++++++++++ app/views/refinery/blog/shared/_post.html.erb | 2 +- 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 app/views/refinery/blog/admin/shared/_locale_picker.html.erb (limited to 'app/views') diff --git a/app/views/refinery/blog/admin/categories/_category.html.erb b/app/views/refinery/blog/admin/categories/_category.html.erb index b7d352f..d31e4e6 100644 --- a/app/views/refinery/blog/admin/categories/_category.html.erb +++ b/app/views/refinery/blog/admin/categories/_category.html.erb @@ -1,7 +1,15 @@
  • - <%= category.title %> -   + <%= category.title.presence || category.translations.detect {|t| t.title.present?}.title %> + + <% category.translations.each do |translation| %> + <% if translation.title.present? %> + <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'), + refinery.edit_blog_admin_category_path(category, :switch_locale => translation.locale), + :class => 'locale' %> + <% end %> + <% end %> + <%= link_to refinery_icon_tag("application_edit.png"), diff --git a/app/views/refinery/blog/admin/categories/_form.html.erb b/app/views/refinery/blog/admin/categories/_form.html.erb index b1cf16c..6b4e20d 100644 --- a/app/views/refinery/blog/admin/categories/_form.html.erb +++ b/app/views/refinery/blog/admin/categories/_form.html.erb @@ -5,6 +5,9 @@ :include_object_name => true } %> + <%= render "/refinery/blog/admin/shared/locale_picker", + :current_locale => Thread.current[:globalize_locale] if Refinery.i18n_enabled? %> +
    <%= f.label :title -%> <%= f.text_field :title, :class => 'larger widest' -%> diff --git a/app/views/refinery/blog/admin/posts/_form.html.erb b/app/views/refinery/blog/admin/posts/_form.html.erb index a977754..b6fc535 100644 --- a/app/views/refinery/blog/admin/posts/_form.html.erb +++ b/app/views/refinery/blog/admin/posts/_form.html.erb @@ -5,6 +5,9 @@ :include_object_name => true } %> + <%= render "/refinery/blog/admin/shared/locale_picker", + :current_locale => Thread.current[:globalize_locale] if Refinery.i18n_enabled? %> +
    <%= f.label :title -%> <%= f.text_field :title, :class => 'larger widest' -%> diff --git a/app/views/refinery/blog/admin/posts/_post.html.erb b/app/views/refinery/blog/admin/posts/_post.html.erb index fea3eb8..781595a 100644 --- a/app/views/refinery/blog/admin/posts/_post.html.erb +++ b/app/views/refinery/blog/admin/posts/_post.html.erb @@ -1,7 +1,16 @@
  • - <%= post.title %> + <%= post.title.presence || post.translations.detect {|t| t.title.present?}.title %> + <% post.translations.each do |translation| %> + <% if translation.title.present? %> + <%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'), + refinery.edit_blog_admin_post_path(post, :switch_locale => translation.locale), + :class => 'locale' %> + <% end %> + <% end %> + + <%= post.published_at.try(:strftime, '%b %d, %Y') || 'draft' %> <%= " by #{post.author.username}" if post.author.present? %> <% if post.draft? %> <%= t('refinery.blog.admin.posts.post.draft') %> diff --git a/app/views/refinery/blog/admin/shared/_locale_picker.html.erb b/app/views/refinery/blog/admin/shared/_locale_picker.html.erb new file mode 100644 index 0000000..e162364 --- /dev/null +++ b/app/views/refinery/blog/admin/shared/_locale_picker.html.erb @@ -0,0 +1,11 @@ + +<% if (locales ||= Refinery::I18n.frontend_locales).present? and locales.many? %> +
      + <% locales.each do |locale| %> + > + <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => "32x22"), + refinery.url_for(:switch_locale => locale) %> + + <% end %> +
    +<% end %> diff --git a/app/views/refinery/blog/shared/_post.html.erb b/app/views/refinery/blog/shared/_post.html.erb index 5b90c8e..40ae70b 100644 --- a/app/views/refinery/blog/shared/_post.html.erb +++ b/app/views/refinery/blog/shared/_post.html.erb @@ -7,7 +7,7 @@ <%= t('created_at', :scope => 'refinery.blog.shared.posts', :when => l(post.published_at.to_date, :format => :short)) %> <%= "#{t('by', :scope => 'refinery.blog.posts.show')} #{post.author.username}" if post.author.present? %>. - <% if (categories = post.categories).any? %> + <% if (categories = post.categories.translated).any? %>