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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a3613df0269cd879899d9d22b5caaac10d81ed99b7cae5817111eabba181aff
4
- data.tar.gz: c003a28fc817883048a004a20bc9d074543542dc2de4eeffd6f8a126452baf4c
3
+ metadata.gz: ab1b17a0db7d116afe2d102f274780cedb4437479a3d70e26315b9b8f7fb513b
4
+ data.tar.gz: 3513c74a1b1455279a7eedb717b0fe95d243931ae66ed3279d978e945a64de3e
5
5
  SHA512:
6
- metadata.gz: 4631f8504116bb3c067832673e5b817ee6dd537c5a0438d360e16774023575a2a3309485560dd2825d48a2bb2dc2cdae50326aa4784dc62a9ae7594149f11bad
7
- data.tar.gz: 87e44b29a116546be43cbf8b45bf65b23d6dae489e2b37dd602b50dcd4b588f845230e577a2de83f378261f99ed4ce71d7bf33f7da0ded698301d055954354f0
6
+ metadata.gz: 361c1dab2068bad0bc506635874b885719dd206420517af6e22dbafc1013fe2fd5a0d61d33a055d5d8058e93541a10e8f4614213cc83c8fcc54a8eac58b4f59c
7
+ data.tar.gz: 31dd5a49cc3d9fab2bb8e8fa908944b49cbd2bac978ad7cb810a3f48683eaf5b80f3380a6c13c02b8ae341930c9d34d1c2f4a3513d74c5bd0ee904ad275c68e0
data/.shipkit.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- previous_version: 1.2.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 = ->(context, block) {}
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 |obj|
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 = obj.translation_scope if obj.respond_to?(:translation_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?(argv1[:literal].to_s) ? @context[argv1[:literal].to_s] : argv1[:literal].to_s
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Liquidum
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt