liquidum 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.shipkit.yml +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +23 -0
- data/lib/liquidum/configuration.rb +5 -1
- data/lib/liquidum/liquid/filters/translate_filter.rb +7 -2
- data/lib/liquidum/liquid/liquid_helpers.rb +4 -1
- data/lib/liquidum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab1b17a0db7d116afe2d102f274780cedb4437479a3d70e26315b9b8f7fb513b
|
|
4
|
+
data.tar.gz: 3513c74a1b1455279a7eedb717b0fe95d243931ae66ed3279d978e945a64de3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 361c1dab2068bad0bc506635874b885719dd206420517af6e22dbafc1013fe2fd5a0d61d33a055d5d8058e93541a10e8f4614213cc83c8fcc54a8eac58b4f59c
|
|
7
|
+
data.tar.gz: 31dd5a49cc3d9fab2bb8e8fa908944b49cbd2bac978ad7cb810a3f48683eaf5b80f3380a6c13c02b8ae341930c9d34d1c2f4a3513d74c5bd0ee904ad275c68e0
|
data/.shipkit.yml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
---
|
|
2
|
-
previous_version: 1.
|
|
2
|
+
previous_version: 1.3.1
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `config.translation_scope` gives the scope of the `t` filter's keys that
|
|
6
|
+
start with a dot, from the Liquid context. Those keys had no scope before.
|
|
7
|
+
- The `t` filter translates with the app's own translations when
|
|
8
|
+
`config.i18n_store` isn't set, instead of failing.
|
|
9
|
+
|
|
5
10
|
- Allow Liquid 5.4 and later (up to 6).
|
|
6
11
|
- Drops describe their variables for editors: `Drop.variables`, the
|
|
7
12
|
`describe` DSL, and `GET /liquidum/variables` with signed roots
|
data/README.md
CHANGED
|
@@ -10,6 +10,29 @@ Basically it's as easy as:
|
|
|
10
10
|
Liquidum.render("{{payload.test}}", assigns: { 'payload' => { 'test' => 'blah' } })
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## Translations
|
|
14
|
+
|
|
15
|
+
The `t` filter translates a key with I18n, in the current locale or the one
|
|
16
|
+
given, with the other arguments interpolated:
|
|
17
|
+
|
|
18
|
+
```liquid
|
|
19
|
+
{{ 'orders.greeting' | t: name: customer.name }}
|
|
20
|
+
{{ 'orders.greeting' | t: name: customer.name, locale: 'nl' }}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
It translates with your app's translations, unless `config.i18n_store` gives
|
|
24
|
+
another backend for the Liquid context. A key that starts with a dot is in the
|
|
25
|
+
scope `config.translation_scope` gives for the context; with a backend that
|
|
26
|
+
includes `I18n::Backend::Cascade` it is then looked up from that scope towards
|
|
27
|
+
the root:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
Liquidum.configure do |config|
|
|
31
|
+
config.i18n_store = ->(context) { I18n::Backend::Chain.new(MyBackend.new, I18n.backend) }
|
|
32
|
+
config.translation_scope = ->(context) { context.registers["template"]&.translation_scope }
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
13
36
|
## Variables for editors
|
|
14
37
|
|
|
15
38
|
Editors can offer the variables a template can use, as a picker or as
|
|
@@ -41,10 +41,14 @@ module Liquidum
|
|
|
41
41
|
# The controller Liquidum's controllers inherit from, to decide who may
|
|
42
42
|
# use them, e.g. "Admin::BaseController". Set it in an initializer.
|
|
43
43
|
option :parent_controller, default: "::ApplicationController"
|
|
44
|
+
# The scope of the `t` filter's keys that start with a dot, from the Liquid
|
|
45
|
+
# context, e.g. ->(context) { context.registers["template"]&.translation_scope }
|
|
46
|
+
option :translation_scope, default: ->(_context) {}, proc: true
|
|
47
|
+
# The I18n backend the `t` filter translates with, from the Liquid context
|
|
44
48
|
attr_writer :i18n_store
|
|
45
49
|
|
|
46
50
|
def initialize
|
|
47
|
-
@i18n_store = ->(
|
|
51
|
+
@i18n_store = ->(_context) { I18n.backend }
|
|
48
52
|
set_defaults!
|
|
49
53
|
end
|
|
50
54
|
|
|
@@ -4,6 +4,11 @@ module TranslateFilter
|
|
|
4
4
|
# Translate text
|
|
5
5
|
#
|
|
6
6
|
# Example:
|
|
7
|
+
# <div class="summary">{{'index.title' | t}}</div>
|
|
8
|
+
#
|
|
9
|
+
# a key that starts with a dot is in the scope config.translation_scope gives
|
|
10
|
+
# (looked up from that scope towards the root, when the backend cascades):
|
|
11
|
+
#
|
|
7
12
|
# <div class="summary">{{'.title' | t}}</div>
|
|
8
13
|
#
|
|
9
14
|
# provide optional locale to translate the text in, if you don't pass it it will use I18n.locale
|
|
@@ -18,7 +23,7 @@ module TranslateFilter
|
|
|
18
23
|
def translate(input, options = {})
|
|
19
24
|
result = nil
|
|
20
25
|
|
|
21
|
-
Liquidum.config.i18n_store(@context) do
|
|
26
|
+
Liquidum.config.i18n_store(@context) do
|
|
22
27
|
locale = options.delete("locale")
|
|
23
28
|
|
|
24
29
|
key = input
|
|
@@ -26,7 +31,7 @@ module TranslateFilter
|
|
|
26
31
|
|
|
27
32
|
if key.start_with?(".")
|
|
28
33
|
key = input[1..-1]
|
|
29
|
-
scope =
|
|
34
|
+
scope = Liquidum.config.translation_scope(@context).presence
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
result = I18n.t(key, locale: locale, scope: scope, cascade: {skip_root: false},
|
|
@@ -47,7 +47,10 @@ module Liquidum
|
|
|
47
47
|
if argv1.key? :quoted
|
|
48
48
|
argv1[:quoted].to_s
|
|
49
49
|
elsif argv1.key? :literal
|
|
50
|
-
@context.key
|
|
50
|
+
# Not @context.key?: since Liquid 5.4 it only finds top-level
|
|
51
|
+
# variables, not paths like account.logo
|
|
52
|
+
value = @context[argv1[:literal].to_s]
|
|
53
|
+
value.nil? ? argv1[:literal].to_s : value
|
|
51
54
|
end
|
|
52
55
|
end
|
|
53
56
|
|
data/lib/liquidum/version.rb
CHANGED