Permalink
Browse files

Merge branch '1.2'

* 1.2:
  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

Conflicts:
	app/controllers/admin/base_controller_decorator.rb
	app/controllers/controller_helpers_decorator.rb
	app/models/shipping_method_decorator.rb
	app/models/spree/product_decorator.rb
  • Loading branch information...
2 parents b07a747 + c431e82 commit acf0cdf21b26fa6f36a048c0db90ad75e091673d @sbounmy sbounmy committed Apr 3, 2013
Showing with 184 additions and 16 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. +1 −1 app/controllers/admin/base_controller_decorator.rb
  17. +2 −2 app/controllers/locale_controller_decorator.rb
  18. +5 −0 app/models/image_decorator.rb
  19. +5 −0 app/models/property_decorator.rb
  20. +6 −5 app/models/spree/product_decorator.rb
  21. +5 −0 app/models/tax_category_decorator.rb
  22. +7 −0 app/overrides/image_add_language_dropdown.rb
  23. +7 −0 app/overrides/property_add_language_dropdown.rb
  24. +18 −0 app/overrides/shipping_method_add_multi_language.rb
  25. +7 −0 app/overrides/tax_category_add_language_dropdown.rb
  26. +10 −3 app/views/spree/admin/shared/_language_dropdown.html.erb
  27. +1 −1 db/migrate/20120620153608_add_translations_to_tax_rates.rb
  28. +1 −1 db/migrate/20120628135204_add_translations_to_shipping_methods.rb
  29. +8 −0 db/migrate/20121024155119_add_translation_to_tax_category.rb
  30. +8 −0 db/migrate/20121025190620_add_translation_to_image.rb
  31. +21 −0 db/migrate/20121029125321_add_description_to_shipping_method.rb
  32. +8 −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,7 +4,7 @@
def locale_suffix(locale)
locale ||= I18n.locale
- I18n.locale == locale.to_sym ? "".to_sym : "_"+ locale
+ I18n.locale == locale ? "" : "_"+ locale
end
private
@@ -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
@@ -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
@@ -65,5 +65,6 @@ def self.like_any(fields, values)
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>
@@ -5,6 +5,6 @@ def up
end
def down
- Spree::TaxRate.drop_translation_table!(:migrate_date => true)
+ Spree::TaxRate.drop_translation_table!(:migrate_data => true)
end
end
@@ -1,6 +1,6 @@
class AddTranslationsToShippingMethods < ActiveRecord::Migration
def up
- Spree::ShippingMethod.create_translation_table!(:name => :string)
+ Spree::ShippingMethod.create_translation_table!(:name => :string, :migrate_data => true)
end
def down
@@ -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,21 @@
+class AddDescriptionToShippingMethod < ActiveRecord::Migration
+ def up
+ change_table :spree_shipping_methods do |t|
+ t.text :description
+ end
+ Spree::ShippingMethod.reset_column_information
+
+ change_table :spree_shipping_method_translations do |t|
+ t.text :description
+ end
+ end
+
+ def down
+ change_table :spree_shipping_method_translations do |t|
+ t.text :description
+ end
+ change_table :spree_shipping_methods do |t|
+ t.remove :description
+ end
+ end
+end
@@ -0,0 +1,8 @@
+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 acf0cdf

Please sign in to comment.