Permalink
Browse files

Merge branch '1.2' of git://github.com/runtimerevolution/spree_multi_…

…lingual into 1.2

* '1.2' of git://github.com/runtimerevolution/spree_multi_lingual:
  Applied changes caused by the security fix in spree 1.2.4.
  Added support for translated product fields searches. When the search is made, only the current locale translation will be searched.
  Added a note about the famfamfam flags.
  Correction to the duplicate method in the product_decorator to avoid failure when locales like 'pt_PT' or 'en_US' exist.
  Corrected migrations.
  Updated added migrations to migrate existing data. Added rake task for the same purpose.
  added flags to the most speaked languages
  added multi language to properties
  added translation to shipping methods
  cleanup image alt_text deface
  fields that can be translated now show a flag
  added multilanguage to alt images
  added multilanguage support for the tax name
  • Loading branch information...
sbounmy committed Apr 2, 2013
2 parents e50af35 + d32064d commit c431e82136e766bec4c8b3e5ca02fd0bd2c949b9
Showing with 207 additions and 17 deletions.
  1. +2 −0 README.md
  2. BIN app/assets/images/spree_multi_lingual/ar.png
  3. BIN app/assets/images/spree_multi_lingual/bn.png
  4. BIN app/assets/images/spree_multi_lingual/cn.png
  5. BIN app/assets/images/spree_multi_lingual/de.png
  6. BIN app/assets/images/spree_multi_lingual/en.png
  7. BIN app/assets/images/spree_multi_lingual/es.png
  8. BIN app/assets/images/spree_multi_lingual/fr.png
  9. BIN app/assets/images/spree_multi_lingual/in.png
  10. BIN app/assets/images/spree_multi_lingual/pt-BR.png
  11. BIN app/assets/images/spree_multi_lingual/pt-PT.png
  12. BIN app/assets/images/spree_multi_lingual/pt.png
  13. BIN app/assets/images/spree_multi_lingual/ru.png
  14. +0 −3 app/assets/stylesheets/admin/spree_multi_lingual.css
  15. +30 −0 app/assets/stylesheets/admin/spree_multi_lingual.css.erb
  16. +2 −2 app/controllers/admin/base_controller_decorator.rb
  17. +2 −2 app/controllers/controller_helpers_decorator.rb
  18. +2 −2 app/controllers/locale_controller_decorator.rb
  19. +5 −0 app/models/image_decorator.rb
  20. +5 −0 app/models/property_decorator.rb
  21. +8 −0 app/models/shipping_method_decorator.rb
  22. +24 −5 app/models/spree/product_decorator.rb
  23. +5 −0 app/models/tax_category_decorator.rb
  24. +7 −0 app/overrides/image_add_language_dropdown.rb
  25. +7 −0 app/overrides/property_add_language_dropdown.rb
  26. +18 −0 app/overrides/shipping_method_add_multi_language.rb
  27. +7 −0 app/overrides/tax_category_add_language_dropdown.rb
  28. +10 −3 app/views/spree/admin/shared/_language_dropdown.html.erb
  29. +8 −0 db/migrate/20121024155119_add_translation_to_tax_category.rb
  30. +8 −0 db/migrate/20121025190620_add_translation_to_image.rb
  31. +16 −0 db/migrate/20121029125321_add_translation_to_shipping_method.rb
  32. +9 −0 db/migrate/20121030142423_add_translation_to_property.rb
  33. +32 −0 lib/tasks/migrate.rake
View
@@ -92,6 +92,8 @@ It uses Globalize3, easy_globalize3_accessors and routing-filter. Thanks to [Tom
SpreeMultiLingual depends on a fork of routing-filter because it supports :exclude option in routes, used for /admin. I hope it this feature can me merged into the original repo.
+The flags are from the flags icon set from famfamfam (http://www.famfamfam.com/).
+
## TODO
1. Make taxons multi languages editable from the taxonomy tree
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,3 +0,0 @@
-/*
- *= require admin/spree_core
-*/
@@ -0,0 +1,30 @@
+/*
+ *= require admin/spree_core
+*/
+
+
+
+input.sml-localized-field[type='text'] {
+ background-position: 100% 50%;
+ background-repeat: no-repeat;
+ padding-right:20px;
+}
+textarea.sml-localized-field {
+ background-position: 0% 2px;
+ background-repeat: no-repeat;
+ padding-top:20px;
+}
+
+
+/*.sml-localized-field{
+ background-image: url(<%= asset_path 'spree_multi_lingual/pt-PT.png' %>);
+}*/
+
+
+.sml-localized-field-pt-PT{
+ background-image: url(<%= asset_path 'spree_multi_lingual/pt-PT.png' %>);
+}
+
+.sml-localized-field-en{
+ background-image: url(<%= asset_path 'spree_multi_lingual/en.png' %>);
+}
@@ -4,13 +4,13 @@
def locale_suffix(locale)
locale ||= I18n.locale
- I18n.locale == locale.to_sym ? "".to_sym : "_"+ locale
+ I18n.locale == locale ? "" : "_"+ locale
end
private
def set_user_language
- I18n.locale = Rails.application.config.i18n.default_locale.to_sym
+ I18n.locale = Rails.application.config.i18n.default_locale
end
end
@@ -12,7 +12,7 @@
# or Rails.application.config.i18n.default_locale
def set_user_language
locale = params[:locale] || session[:locale] || I18n.locale || Spree::Config[:default_locale] || Rails.application.config.i18n.default_locale
- locale = I18n.default_locale unless locale && I18n.available_locales.include?(locale.to_sym)
- I18n.locale = locale.to_sym
+ locale = I18n.default_locale unless locale && I18n.available_locales.map(&:to_s).include?(locale)
+ I18n.locale = locale
end
end
@@ -5,8 +5,8 @@ def set
session['user_return_to'] = request.referer
end
- if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
- session[:locale] = I18n.locale = params[:locale].to_sym
+ if params[:locale] && I18n.available_locales.map(&:to_s).include?(params[:locale])
+ session[:locale] = I18n.locale = params[:locale]
flash.notice = t(:locale_changed)
else
flash[:error] = t(:locale_not_changed)
@@ -0,0 +1,5 @@
+module Spree
+ Image.class_eval do
+ translates :alt
+ end
+end
@@ -0,0 +1,5 @@
+module Spree
+ Property.class_eval do
+ translates :presentation
+ end
+end
@@ -0,0 +1,8 @@
+module Spree
+ ShippingMethod.class_eval do
+ translates :name, :description
+
+ attr_accessible :description
+
+ end
+end
@@ -15,11 +15,11 @@ def duplicate
meta_keywords_locale = read_attribute(:meta_keywords, :locale => locale)
permalink_locale = (I18n.t :copy_of_permalink, :locale => locale) + read_attribute(:permalink, :locale => locale)
- eval("p.name"+locale_suffix+" = name_locale")
- eval("p.description"+locale_suffix+" = description_locale")
- eval("p.meta_description"+locale_suffix+" = meta_description_locale")
- eval("p.meta_keywords"+locale_suffix+" = meta_keywords_locale")
- eval("p.permalink"+locale_suffix+" = permalink_locale")
+ p.send("name"+locale_suffix+"=", name_locale)
+ p.send("description"+locale_suffix+"=", description_locale)
+ p.send("meta_description"+locale_suffix+"=", meta_description_locale)
+ p.send("meta_keywords"+locale_suffix+"=", meta_keywords_locale)
+ p.send("permalink"+locale_suffix+"=", permalink_locale)
end
p.deleted_at = nil
@@ -44,5 +44,24 @@ def duplicate
p.save!
p
end
+
+ def self.like_any(fields, values)
+ has_translated_fields = false
+ where_str = fields.map do |field|
+ if self.translated?(field)
+ has_translated_fields = true
+ next Array.new(values.size, "#{self.translation_class.quoted_table_name}.#{field} #{LIKE} ?").join(' OR ')
+ end
+ next Array.new(values.size, "#{self.quoted_table_name}.#{field} #{LIKE} ?").join(' OR ')
+ end
+ where_str = where_str.join(' OR ')
+ self_scope = self
+ #only use translations scope if we are searching translated fields.
+ if has_translated_fields
+ self_scope = self_scope.with_translations(I18n.locale)
+ end
+ self_scope.where([where_str, values.map { |value| "%#{value}%" } * fields.size].flatten)
+ end
+
end
@@ -0,0 +1,5 @@
+module Spree
+ TaxCategory.class_eval do
+ translates :name
+ end
+end
@@ -0,0 +1,7 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/images/edit",
+ :insert_before => "[data-hook='edit_image']",
+ :text => '<%= render "spree/admin/shared/language_dropdown", :object => @image -%>',
+ :name => "image_add_language_dropdown"
+)
+
@@ -0,0 +1,7 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/properties/edit",
+ :insert_before=> "code[erb-loud]:contains(\"render :partial => 'form'\")",
+ :text => '<%= render "spree/admin/shared/language_dropdown", :object => @property -%>',
+ :name => "property_add_language_dropdown"
+)
+
@@ -0,0 +1,18 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/shipping_methods/edit",
+ :insert_before => "code[erb-loud]:contains(\"render :partial => 'form'\")",
+ :text => '<%= render "spree/admin/shared/language_dropdown", :object => @shipping_method -%>',
+ :name => "shipping_method_add_language_dropdown",
+ :original => '8a9ce4cf5ad1cd0f240dcf314f1ffd8bb51bbc91'
+)
+
+Deface::Override.new(
+ :virtual_path => "spree/admin/shipping_methods/_form",
+ :insert_before => "code[erb-loud]:contains('f.field_container :zone_id do')",
+ :text => "<%= f.field_container :description do %> \
+ <%= f.label :description, t(:description) %> <br /> \
+ <%= f.text_area :description, {:cols => 60, :rows=>2, :class=>'fullwidth', :style=>'height:auto'} %> \
+ <%= f.error_message_on :description %> \
+ <% end %>",
+ :name => "shipping_method_description_multi_indicator"
+)
@@ -0,0 +1,7 @@
+Deface::Override.new(
+ :virtual_path => "spree/admin/tax_categories/edit",
+# :insert_before => "[data-hook='admin_tax_category_form_fields']",
+ :insert_after => "code[erb-loud]:contains('form_for')",
+ :text => '<%= render "spree/admin/shared/language_dropdown", :object => @tax_category -%>',
+ :name => "tax_category_add_language_dropdown"
+)
@@ -3,18 +3,25 @@
object_prefix = "#{object_name}_"
%>
-<%= select("currently_modified_language", "lang", SpreeMultiLingual.languages.collect {|l| l}, {selected: I18n.locale}, {id: "spree_multi_lingual_dropdown"}) %>
+<%= select("currently_modified_language", "lang", SpreeMultiLingual.languages.collect {|l| l }, {selected: I18n.locale}, {id: "spree_multi_lingual_dropdown"}) %>
<script>
window.spree_multi_lingual = {};
window.spree_multi_lingual.translated_fields = <%= raw klass.translated_attribute_names.map { |f| object_prefix + f.to_s } %>;
window.spree_multi_lingual.backend_locale = "<%= I18n.locale -%>";
window.spree_multi_lingual.translated_fields_values = [];
+
+ $(function(){
+ $.each(window.spree_multi_lingual.translated_fields, function(i,v){
+ $('#'+v).addClass('sml-localized-field-<%= I18n.locale %>');
+ $('#'+v).addClass('sml-localized-field');
+ });
+ });
+
<% klass.translated_attribute_names.each do |f| %>
<% SpreeMultiLingual.languages.each do |lang| %>
window.spree_multi_lingual.translated_fields_values['<%= "#{object_prefix}#{f}_#{lang}" -%>'] = '<%= escape_javascript(object.send("#{f}_#{lang}")).html_safe if !object.send("#{f}_#{lang}").nil? -%>';
<% end %>
-
<% if object.class.to_s == "Spree::OptionType" %>
<% number_of_values = object.option_values.size %>
@@ -42,4 +49,4 @@
<% end %>
<% end %>
-</script>
+</script>
@@ -0,0 +1,8 @@
+class AddTranslationToTaxCategory < ActiveRecord::Migration
+ def up
+ Spree::TaxCategory.create_translation_table!( { :name => :string }, { :migrate_data => true } )
+ end
+ def down
+ Spree::TaxCategory.drop_translation_table!
+ end
+end
@@ -0,0 +1,8 @@
+class AddTranslationToImage < ActiveRecord::Migration
+ def up
+ Spree::Image.create_translation_table!( { :alt => :string }, { :migrate_data => true } )
+ end
+ def down
+ Spree::Image.drop_translation_table!
+ end
+end
@@ -0,0 +1,16 @@
+# This migration comes from spree_multi_lingual (originally 20121029125321)
+class AddTranslationToShippingMethod < ActiveRecord::Migration
+ def up
+ change_table :spree_shipping_methods do |t|
+ t.text :description
+ end
+ Spree::ShippingMethod.reset_column_information
+ Spree::ShippingMethod.create_translation_table!( { :name => :string, :description => :text }, { :migrate_data => true } )
+ end
+ def down
+ Spree::ShippingMethod.drop_translation_table!
+ change_table :spree_shipping_methods do |t|
+ t.remove :description
+ end
+ end
+end
@@ -0,0 +1,9 @@
+# This migration comes from spree_multi_lingual (originally 20121029125321)
+class AddTranslationToProperty < ActiveRecord::Migration
+ def up
+ Spree::Property.create_translation_table!( { :presentation => :string }, { :migrate_data => true } )
+ end
+ def down
+ Spree::Property.drop_translation_table!
+ end
+end
View
@@ -0,0 +1,32 @@
+namespace :spree_multi_lingual do
+ namespace :migrations do
+
+ desc "Migrate data inserted in the system before the extension was added."
+ task :migrate_data => :environment do |t, args|
+
+ def move_data_to_translation_table(model)
+ model.find_each do |record|
+ untranslated_attributes = record.untranslated_attributes
+ translation = record.translations.build(:locale => I18n.default_locale)
+ model.translated_attribute_names.each do |attribute|
+ translation[attribute] = untranslated_attributes[attribute.to_s]
+ end
+ translation.save!
+ end
+ end
+
+ move_data_to_translation_table(Spree::Product)
+ move_data_to_translation_table(Spree::Taxonomy)
+ move_data_to_translation_table(Spree::Taxon)
+ move_data_to_translation_table(Spree::OptionType)
+ move_data_to_translation_table(Spree::OptionValue)
+ move_data_to_translation_table(Spree::ProductProperty)
+ move_data_to_translation_table(Spree::TaxCategory)
+ move_data_to_translation_table(Spree::Image)
+ move_data_to_translation_table(Spree::ShippingMethod)
+ move_data_to_translation_table(Spree::Property)
+
+ end
+
+ end
+end

0 comments on commit c431e82

Please sign in to comment.