phraseapp-in-context-editor-ruby 2.1.1 → 3.1.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: 1928034119cb6375765fd9dd82f1d66c859d070482da61e647abc72ddb06d6d9
4
- data.tar.gz: 96ad3d6b6a686e1dbd5104cb1f8b6663072b3879142e308978ccf89d4cbe547d
3
+ metadata.gz: 900986756f3ba71519a83b5168774f3fbcccde7956535ced2a907e1a1725978c
4
+ data.tar.gz: 33ed4e6bc473b1b456a4955f5253aeb637864fde544968051f88d95948a21666
5
5
  SHA512:
6
- metadata.gz: cd71b31c0f1f454af7367d0d4d194c5889613bb83d9ea166199f8634e45edd01c76677dad2911205e1bdf2b8fd95994e7ea7f5fadcb29a68e4088f77ceee9825
7
- data.tar.gz: 19189182859a08240b7cfddab04b63f35c96be6c64cd2e71f6af47010b437ec44b62206fb45ef7e55a8718cd16722b8cffb8f8b249075803f6f2f82dc5fd96a3
6
+ metadata.gz: 4eb5593cd10987c04b61726aa051b6c962b3b1f2bf83841f1ab0c3f80c319881cf71517f47a5f1c2ca3c73c6e4d86eca90532b87f476b887a11c3b72bdae255e
7
+ data.tar.gz: 0eed67e1f200e262044f3cb936f3e88c1f1bea485565345ad3a24f1f6ca34109a61b20878500f6911b12f9d69e81f2eac0b8dcfa26784dddeaf673b2008d821a
@@ -1,10 +1,10 @@
1
1
  name: Test
2
- on: [ push ]
2
+ on: [push, pull_request]
3
3
  jobs:
4
4
  test:
5
5
  strategy:
6
6
  matrix:
7
- ruby: [ 3.1, 3.2 ]
7
+ ruby: [3.1, 3.2]
8
8
  runs-on: ubuntu-latest
9
9
  steps:
10
10
  - uses: actions/checkout@v4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ # [3.1.0](https://github.com/phrase/phraseapp-in-context-editor-ruby/compare/v3.0.1...v3.1.0) (2024-06-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * Add config option to ignore keys ([#82](https://github.com/phrase/phraseapp-in-context-editor-ruby/issues/82)) ([657b9f3](https://github.com/phrase/phraseapp-in-context-editor-ruby/commit/657b9f3ebce1ca2a364af1b9b84b0b28ee733983))
7
+
8
+ ## [3.0.1](https://github.com/phrase/phraseapp-in-context-editor-ruby/compare/v3.0.0...v3.0.1) (2024-06-14)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Adjust module name to fix semantic release bumps ([#84](https://github.com/phrase/phraseapp-in-context-editor-ruby/issues/84)) ([f97ed2d](https://github.com/phrase/phraseapp-in-context-editor-ruby/commit/f97ed2d81a755fa97e3a9a908e42eb8f99e78cc2))
14
+
15
+ # [3.0.0](https://github.com/phrase/phraseapp-in-context-editor-ruby/compare/v2.1.2...v3.0.0) (2024-05-21)
16
+
17
+
18
+ * BREAKING CHANGE: Use ruby 2.7 'Forward all arguments' syntax: (...) to forward arguments (#78) ([99ae28e](https://github.com/phrase/phraseapp-in-context-editor-ruby/commit/99ae28e2f6fea0ba2ba0eec6eca54a043e21d121)), closes [#78](https://github.com/phrase/phraseapp-in-context-editor-ruby/issues/78)
19
+
20
+
21
+ ### BREAKING CHANGES
22
+
23
+ * Hash arguments will throw an error. Keyword arguments must be used instead.
24
+
25
+ ## [2.1.2](https://github.com/phrase/phraseapp-in-context-editor-ruby/compare/v2.1.1...v2.1.2) (2024-05-21)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * Ruby 3.0 keyword argument error when ICE is enabled ([#79](https://github.com/phrase/phraseapp-in-context-editor-ruby/issues/79)) ([d0efad8](https://github.com/phrase/phraseapp-in-context-editor-ruby/commit/d0efad859b83b7ac78873e012aafcac2d1856481))
31
+
1
32
  ## [2.1.1](https://github.com/phrase/phraseapp-in-context-editor-ruby/compare/v2.1.0...v2.1.1) (2024-04-23)
2
33
 
3
34
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phraseapp-in-context-editor-ruby (2.1.0)
4
+ phraseapp-in-context-editor-ruby (3.0.0)
5
5
  i18n (~> 1.0)
6
6
  json (~> 2.0)
7
7
  request_store (~> 1.2)
@@ -9,6 +9,10 @@ PhraseApp::InContextEditor.configure do |config|
9
9
  config.account_id = "<%= options[:account_id] %>"
10
10
  config.datacenter = "eu"
11
11
 
12
+ # Configure an array of key names that should not be handled
13
+ # by the In-Context-Editor.
14
+ # config.ignored_keys = ["number.*", "foo.bar"]
15
+
12
16
  # Phrase uses decorators to generate a unique identification key
13
17
  # in context of your document. However, this might result in conflicts
14
18
  # with other libraries (e.g. client-side template engines) that use a similar syntax.
@@ -1,8 +1,8 @@
1
1
  if defined?(I18n)
2
2
  module I18n
3
3
  class << self
4
- def translate_with_phraseapp(*args)
5
- PhraseApp::InContextEditor.backend.translate(*args)
4
+ def translate_with_phraseapp(...)
5
+ PhraseApp::InContextEditor.backend.translate(...)
6
6
  end
7
7
  alias_method :translate_without_phraseapp, :translate
8
8
  alias_method :translate, :translate_with_phraseapp
@@ -3,47 +3,32 @@ require_relative "delegate/i18n_delegate"
3
3
  module PhraseApp
4
4
  module InContextEditor
5
5
  class BackendService
6
- attr_accessor :blacklisted_keys
7
-
8
6
  def initialize(args = {})
9
7
  self
10
8
  end
11
9
 
12
- def translate(*args)
13
- if to_be_translated_without_phraseapp?(args)
14
- # *Ruby 2.7+ keyword arguments warning*
15
- #
16
- # This method uses keyword arguments.
17
- # There is a breaking change in ruby that produces warning with ruby 2.7 and won't work as expected with ruby 3.0
18
- # The "hash" parameter must be passed as keyword argument.
19
- #
20
- # Good:
21
- # I18n.t(:salutation, :gender => 'w', :name => 'Smith')
22
- # I18n.t(:salutation, **{ :gender => 'w', :name => 'Smith' })
23
- # I18n.t(:salutation, **any_hash)
24
- #
25
- # Bad:
26
- # I18n.t(:salutation, { :gender => 'w', :name => 'Smith' })
27
- # I18n.t(:salutation, any_hash)
28
- #
29
- kw_args = args[1]
30
- if kw_args.present?
31
- I18n.translate_without_phraseapp(args[0], **kw_args)
32
- else
33
- I18n.translate_without_phraseapp(args[0])
34
- end
10
+ def translate(...)
11
+ if to_be_translated_without_phraseapp?(...)
12
+ I18n.translate_without_phraseapp(...)
35
13
  else
36
- phraseapp_delegate_for(args)
14
+ phraseapp_delegate_for(...)
37
15
  end
38
16
  end
39
17
 
40
18
  protected
41
19
 
42
- def to_be_translated_without_phraseapp?(args)
43
- PhraseApp::InContextEditor.disabled? || has_been_forced_to_resolve_with_phraseapp?(args)
20
+ def to_be_translated_without_phraseapp?(...)
21
+ PhraseApp::InContextEditor.disabled? || ignored_key?(...) || has_been_forced_to_resolve_with_phraseapp?(...)
22
+ end
23
+
24
+ def ignored_key?(*args)
25
+ key = given_key_from_args(args)
26
+ PhraseApp::InContextEditor.ignored_keys.any? do |ignored_key|
27
+ key.to_s[/\A#{ignored_key.gsub("*", ".*")}\Z/]
28
+ end
44
29
  end
45
30
 
46
- def has_been_forced_to_resolve_with_phraseapp?(args)
31
+ def has_been_forced_to_resolve_with_phraseapp?(*args)
47
32
  (args.last.is_a?(Hash) && args.last[:resolve] == false)
48
33
  end
49
34
 
@@ -51,11 +36,11 @@ module PhraseApp
51
36
  extract_normalized_key_from_args(args)
52
37
  end
53
38
 
54
- def phraseapp_delegate_for(args)
39
+ def phraseapp_delegate_for(*args)
55
40
  key = given_key_from_args(args)
56
41
  return nil unless present?(key)
57
42
 
58
- options = args[1].nil? ? {} : args[1]
43
+ options = options_from_args(args)
59
44
  PhraseApp::InContextEditor::Delegate::I18nDelegate.new(key, options, args)
60
45
  end
61
46
 
@@ -9,7 +9,8 @@ module PhraseApp
9
9
  backend: PhraseApp::InContextEditor::BackendService.new,
10
10
  prefix: "{{__",
11
11
  suffix: "__}}",
12
- origin: "in-context-editor-ruby"
12
+ origin: "in-context-editor-ruby",
13
+ ignored_keys: []
13
14
  }.freeze
14
15
 
15
16
  CONFIG_OPTIONS.each do |option, default_value|
@@ -4,7 +4,7 @@ module PhraseApp
4
4
  module InContextEditor
5
5
  module Delegate
6
6
  class I18nDelegate < Base
7
- attr_accessor :key, :display_key, :options, :api_client, :fallback_keys, :original_args
7
+ attr_accessor :key, :display_key
8
8
 
9
9
  def initialize(key, options = {}, original_args = nil)
10
10
  @key = key
@@ -24,7 +24,7 @@ module PhraseApp
24
24
  data.send(*args, &block)
25
25
  else
26
26
  self.class.log "You tried to execute the missing method ##{args.first} on key #{@key} which is not supported. Please make sure you treat your translations as strings only."
27
- original_translation = ::I18n.translate_without_phraseapp(*@original_args)
27
+ original_translation = ::I18n.translate_without_phraseapp(*@original_args, **@options)
28
28
  original_translation.send(*args, &block)
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
- module PhraseApp
2
- VERSION = "2.1.1"
1
+ module PhraseappInContextEditor
2
+ VERSION = "3.1.0"
3
3
  end
@@ -37,6 +37,10 @@ module PhraseApp
37
37
  config.datacenter
38
38
  end
39
39
 
40
+ def ignored_keys
41
+ config.ignored_keys
42
+ end
43
+
40
44
  def enabled=(value)
41
45
  config.enabled = value
42
46
  end
@@ -4,7 +4,7 @@ require "./lib/phraseapp-in-context-editor-ruby/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phraseapp-in-context-editor-ruby"
7
- s.version = PhraseApp::VERSION
7
+ s.version = PhraseappInContextEditor::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.required_ruby_version = ">= 3.1.0"
10
10
  s.authors = ["Phrase"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phraseapp-in-context-editor-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phrase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-23 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json