Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix backwards compatibility for translations (#12049)

Łukasz Adamczyk0d2d44e3d206
diff --git a/core/app/models/spree/option_type.rb b/core/app/models/spree/option_type.rb
index 09b20857c5..42d5aadff2 100644
--- a/core/app/models/spree/option_type.rb
+++ b/core/app/models/spree/option_type.rb
@@ -7,8 +7,13 @@ module Spree
include Spree::Webhooks::HasWebhooks
end
- TRANSLATABLE_FIELDS = %i[presentation].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ if Spree.always_use_translations?
+ TRANSLATABLE_FIELDS = %i[name presentation].freeze
+ translates(*TRANSLATABLE_FIELDS)
+ else
+ TRANSLATABLE_FIELDS = %i[presentation].freeze
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ end
acts_as_list
auto_strip_attributes :name, :presentation
diff --git a/core/app/models/spree/option_value.rb b/core/app/models/spree/option_value.rb
index d01b46d2e4..7a18d6150d 100644
--- a/core/app/models/spree/option_value.rb
+++ b/core/app/models/spree/option_value.rb
@@ -6,8 +6,13 @@ module Spree
include Spree::Webhooks::HasWebhooks
end
- TRANSLATABLE_FIELDS = %i[presentation].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ if Spree.always_use_translations?
+ TRANSLATABLE_FIELDS = %i[name presentation].freeze
+ translates(*TRANSLATABLE_FIELDS)
+ else
+ TRANSLATABLE_FIELDS = %i[presentation].freeze
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ end
belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_values
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index b2cd1a6ff6..168adde4d5 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -39,7 +39,7 @@ module Spree
purchasable? in_stock? backorderable?]
TRANSLATABLE_FIELDS = %i[name description slug meta_description meta_keywords meta_title].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
self::Translation.class_eval do
before_save :set_slug
diff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rb
index 23c69d3721..81494a36ef 100644
--- a/core/app/models/spree/product_property.rb
+++ b/core/app/models/spree/product_property.rb
@@ -3,8 +3,13 @@ module Spree
include Spree::FilterParam
include Spree::TranslatableResource
- TRANSLATABLE_FIELDS = %i[value].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ if Spree.always_use_translations?
+ TRANSLATABLE_FIELDS = %i[value filter_param].freeze
+ translates(*TRANSLATABLE_FIELDS)
+ else
+ TRANSLATABLE_FIELDS = %i[value].freeze
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ end
self::Translation.class_eval do
auto_strip_attributes :value
diff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rb
index 91ac2c8952..3b7bfb01b2 100644
--- a/core/app/models/spree/property.rb
+++ b/core/app/models/spree/property.rb
@@ -7,8 +7,13 @@ module Spree
include Spree::Webhooks::HasWebhooks
end
- TRANSLATABLE_FIELDS = %i[presentation].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ if Spree.always_use_translations?
+ TRANSLATABLE_FIELDS = %i[name presentation filter_param].freeze
+ translates(*TRANSLATABLE_FIELDS)
+ else
+ TRANSLATABLE_FIELDS = %i[presentation].freeze
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ end
self::Translation.class_eval do
auto_strip_attributes :presentation
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index e9e1681af7..535e9454a5 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -11,7 +11,7 @@ module Spree
TRANSLATABLE_FIELDS = %i[name meta_description meta_keywords seo_title facebook
twitter instagram customer_support_email description
address contact_phone new_order_notifications_email].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
self::Translation.class_eval do
acts_as_paranoid
diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb
index 9cdb89f9db..092a08b93a 100644
--- a/core/app/models/spree/taxon.rb
+++ b/core/app/models/spree/taxon.rb
@@ -60,7 +60,7 @@ module Spree
scope :for_stores, ->(stores) { joins(:taxonomy).where(spree_taxonomies: { store_id: stores.ids }) }
TRANSLATABLE_FIELDS = %i[name description permalink].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
self::Translation.class_eval do
alias_attribute :slug, :permalink
diff --git a/core/app/models/spree/taxonomy.rb b/core/app/models/spree/taxonomy.rb
index 4e48c46d49..3ce1a5858b 100644
--- a/core/app/models/spree/taxonomy.rb
+++ b/core/app/models/spree/taxonomy.rb
@@ -7,7 +7,7 @@ module Spree
end
TRANSLATABLE_FIELDS = %i[name].freeze
- translates(*TRANSLATABLE_FIELDS, column_fallback: true)
+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)
acts_as_list
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index fa52c845af..9a8f7a5acd 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -76,6 +76,10 @@ module Spree
end
end
+ def self.always_use_translations?
+ Spree::RuntimeConfig.always_use_translations
+ end
+
def self.use_translations?
Spree::RuntimeConfig.always_use_translations || I18n.default_locale != I18n.locale
end