spree_core 4.6.0 → 4.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/spree/translatable_resource_slug.rb +1 -3
- data/app/models/spree/taxon.rb +5 -2
- data/app/services/spree/locales/set_fallback_locale_for_store.rb +16 -0
- data/config/initializers/mobility.rb +1 -3
- data/lib/mobility/plugins/store_based_fallbacks.rb +55 -0
- data/lib/spree/core/controller_helpers/locale.rb +7 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree_core.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5c1992fb7f20f237e3d088cc7c0c79692efb72eaec1e654069ee5b8aeeb846
|
4
|
+
data.tar.gz: 7dd674422290e6570f1b8bb116bd541cac61cbb403402a5996d829b304dac604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 586c58de60df801c9f4e54983a929f8c507cb8b05c8161ff3f82bc0780a3a64ee33cc42d1ffa01dbea9ed7dce9dda4ced801ba0298b326e255d38314d1286539
|
7
|
+
data.tar.gz: 1aeebb1b70bd971a5589f265903a00cd9d6d3c38843968668000d7bf5277832280a2f3b6d7774d73845f2d45f72166873bfc01c493171f0bce973c4cc374c458
|
@@ -4,12 +4,10 @@ module Spree
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
def localized_slugs_for_store(store)
|
7
|
-
localized_slugs = Hash[translations.pluck(:locale, :slug)]
|
8
|
-
default_locale = store.default_locale
|
9
7
|
supported_locales = store.supported_locales_list
|
10
8
|
|
11
9
|
supported_locales.each_with_object({}) do |locale, hash|
|
12
|
-
hash[locale] =
|
10
|
+
hash[locale] = I18n.with_locale(locale) { slug }
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
data/app/models/spree/taxon.rb
CHANGED
@@ -13,6 +13,7 @@ module Spree
|
|
13
13
|
extend FriendlyId
|
14
14
|
friendly_id :permalink, slug_column: :permalink, use: :history
|
15
15
|
before_validation :set_permalink, on: :create, if: :name
|
16
|
+
alias_attribute :slug, :permalink
|
16
17
|
|
17
18
|
acts_as_nested_set dependent: :destroy
|
18
19
|
|
@@ -66,10 +67,12 @@ module Spree
|
|
66
67
|
|
67
68
|
def set_permalink
|
68
69
|
parent = translated_model.parent
|
70
|
+
name_with_fallback = name || translated_model.name
|
71
|
+
|
69
72
|
if parent.present?
|
70
|
-
self.permalink = [parent.permalink, (permalink.blank? ?
|
73
|
+
self.permalink = [parent.permalink, (permalink.blank? ? name_with_fallback.to_url : permalink.split('/').last)].join('/')
|
71
74
|
else
|
72
|
-
self.permalink =
|
75
|
+
self.permalink = name_with_fallback.to_url if permalink.blank?
|
73
76
|
end
|
74
77
|
end
|
75
78
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
module Locales
|
3
|
+
class SetFallbackLocaleForStore
|
4
|
+
def call(store:)
|
5
|
+
store_default_locale = store.default_locale
|
6
|
+
fallbacks = store.supported_locales_list.each_with_object({}) do |locale, object|
|
7
|
+
object[locale] = [store_default_locale]
|
8
|
+
end
|
9
|
+
|
10
|
+
fallbacks_instance = I18n::Locale::Fallbacks.new(fallbacks)
|
11
|
+
|
12
|
+
Mobility.store_based_fallbacks = fallbacks_instance
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'concurrent'
|
4
|
+
require 'mobility'
|
5
|
+
|
6
|
+
# The default implementation in the Mobility gem requires fallbacks to be defined when booting the application.
|
7
|
+
# This patch allows to dynamically reconfigure translations fallbacks, by setting Mobility.store_based_fallbacks attribute.
|
8
|
+
# The implementation is based on the default fallbacks plugin, with some changes around fetching the list of fallbacks to be used.
|
9
|
+
# https://github.com/shioyama/mobility/blob/master/lib/mobility/plugins/fallbacks.rb
|
10
|
+
module Mobility
|
11
|
+
@store_based_fallbacks = Concurrent::ThreadLocalVar.new(I18n::Locale::Fallbacks.new)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def store_based_fallbacks
|
15
|
+
@store_based_fallbacks.value
|
16
|
+
end
|
17
|
+
|
18
|
+
def store_based_fallbacks=(value)
|
19
|
+
@store_based_fallbacks.value = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Plugins
|
24
|
+
module StoreBasedFallbacks
|
25
|
+
extend ::Mobility::Plugin
|
26
|
+
|
27
|
+
default true
|
28
|
+
requires :backend, include: :before
|
29
|
+
|
30
|
+
# Applies fallbacks plugin to attributes. Completely disables fallbacks
|
31
|
+
# on model if option is +false+.
|
32
|
+
included_hook do |_, backend_class|
|
33
|
+
unless options[:fallbacks] == false
|
34
|
+
backend_class.include(BackendInstanceMethods)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module BackendInstanceMethods
|
39
|
+
def read(locale, fallback: true, **kwargs)
|
40
|
+
return super(locale, **kwargs) if !fallback || kwargs[:locale]
|
41
|
+
|
42
|
+
locales = Mobility.store_based_fallbacks[locale]
|
43
|
+
locales.each do |fallback_locale|
|
44
|
+
value = super(fallback_locale, **kwargs)
|
45
|
+
return value if Util.present?(value)
|
46
|
+
end
|
47
|
+
|
48
|
+
super(locale, **kwargs)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
register_plugin(:store_based_fallbacks, StoreBasedFallbacks)
|
54
|
+
end
|
55
|
+
end
|
@@ -6,6 +6,7 @@ module Spree
|
|
6
6
|
|
7
7
|
included do
|
8
8
|
before_action :set_locale
|
9
|
+
before_action :set_fallback_locale
|
9
10
|
|
10
11
|
if defined?(helper_method)
|
11
12
|
helper_method :supported_locales
|
@@ -21,6 +22,12 @@ module Spree
|
|
21
22
|
I18n.locale = current_locale
|
22
23
|
end
|
23
24
|
|
25
|
+
def set_fallback_locale
|
26
|
+
return unless respond_to?(:current_store) && current_store.present?
|
27
|
+
|
28
|
+
Spree::Locales::SetFallbackLocaleForStore.new.call(store: current_store)
|
29
|
+
end
|
30
|
+
|
24
31
|
def current_locale
|
25
32
|
@current_locale ||= if user_locale?
|
26
33
|
try_spree_current_user.selected_locale
|
data/lib/spree/core/version.rb
CHANGED
data/lib/spree_core.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.6.
|
4
|
+
version: 4.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Schofield
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -801,6 +801,7 @@ files:
|
|
801
801
|
- app/services/spree/line_items/destroy.rb
|
802
802
|
- app/services/spree/line_items/helper.rb
|
803
803
|
- app/services/spree/line_items/update.rb
|
804
|
+
- app/services/spree/locales/set_fallback_locale_for_store.rb
|
804
805
|
- app/services/spree/orders/approve.rb
|
805
806
|
- app/services/spree/orders/cancel.rb
|
806
807
|
- app/services/spree/payments/create.rb
|
@@ -923,6 +924,7 @@ files:
|
|
923
924
|
- lib/generators/spree/dummy_model/templates/model.rb.tt
|
924
925
|
- lib/generators/spree/install/install_generator.rb
|
925
926
|
- lib/generators/spree/install/templates/config/initializers/spree.rb
|
927
|
+
- lib/mobility/plugins/store_based_fallbacks.rb
|
926
928
|
- lib/spree/core.rb
|
927
929
|
- lib/spree/core/components.rb
|
928
930
|
- lib/spree/core/configuration.rb
|
@@ -1077,9 +1079,9 @@ licenses:
|
|
1077
1079
|
- BSD-3-Clause
|
1078
1080
|
metadata:
|
1079
1081
|
bug_tracker_uri: https://github.com/spree/spree/issues
|
1080
|
-
changelog_uri: https://github.com/spree/spree/releases/tag/v4.6.
|
1082
|
+
changelog_uri: https://github.com/spree/spree/releases/tag/v4.6.1
|
1081
1083
|
documentation_uri: https://dev-docs.spreecommerce.org/
|
1082
|
-
source_code_uri: https://github.com/spree/spree/tree/v4.6.
|
1084
|
+
source_code_uri: https://github.com/spree/spree/tree/v4.6.1
|
1083
1085
|
post_install_message:
|
1084
1086
|
rdoc_options: []
|
1085
1087
|
require_paths:
|