isodoc-i18n 1.4.1 → 1.4.2

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: e08e5e4a6c9b89a5f628ee426ce22f8bcdbae97e7cccd4411f4962844d29b231
4
- data.tar.gz: 9d8cbc5526c1d8aabe9db00c25deeb581a3604358b50b18e6f5a9bb7faab6909
3
+ metadata.gz: 02e65f54740c83c1d9698623c18711219680d6541f88e2cd0aaa62d3595c103d
4
+ data.tar.gz: f57b0e7bf29a2d02576dda04b3d7b34ded97a42ec382ebdbc9caefb12a1aa17b
5
5
  SHA512:
6
- metadata.gz: 3880d68a1f094ab500840e74767f970af57fca01a12ae751da68e9cdc72ba00df9139516df3c74dda5059114fe723b800c057c665efdd485e44aa9a247cdde22
7
- data.tar.gz: 80643511d523a3535293a2b7b82e60fe81a8910dbe9fc336cf8a4ab95a9763b1adf1375f802f5b36177a6e4570c51688b803576f7d2d39b8fc7c29e894d2f235
6
+ metadata.gz: b0a869f0df1ef445e5f18d336d0d3f18968e7055444e81535d7da4219a7c24f4e370ea45e0033d1ed2766d8fc5ea2c577f74ea07c232fc6217ff236aacc65e8e
7
+ data.tar.gz: 801f9ccb9c81c372c77834ad3667b88491f0aa1429c588e1a8c1854fc5ca8f1a817607de4bd0c44ed1d02f2a3984d5c336714692cff31c860d6c14a658502e9b
data/isodoc-i18n.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "metanorma-utils", ">= 1.7.0"
29
29
  spec.add_dependency "twitter_cldr"
30
30
 
31
- spec.add_development_dependency "canon"
31
+ spec.add_development_dependency "canon", "= 0.1.3"
32
32
  spec.add_development_dependency "debug"
33
33
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
34
34
  spec.add_development_dependency "guard", "~> 2.14"
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.4.1".freeze
3
+ VERSION = "1.4.2".freeze
4
4
  end
5
5
  end
@@ -7,10 +7,13 @@ module IsoDoc
7
7
 
8
8
  def load_yaml(lang, script, i18nyaml = nil, i18nhash = nil)
9
9
  ret = load_yaml1(lang, script)
10
- i18nyaml and
11
- return postprocess(ret.deep_merge(YAML.load_file(i18nyaml)))
10
+ if i18nyaml
11
+ Array(i18nyaml).compact.each do |y|
12
+ ret = ret.deep_merge(YAML.load_file(y))
13
+ end
14
+ return postprocess(ret)
15
+ end
12
16
  i18nhash and return postprocess(ret.deep_merge(i18nhash))
13
-
14
17
  postprocess(ret)
15
18
  end
16
19
 
@@ -38,7 +41,7 @@ module IsoDoc
38
41
  def resolve_string_references(str, labels)
39
42
  # Match patterns like #{self["key"]["subkey"]} or #{self.key.subkey}
40
43
  # Allow spaces around the self expression
41
- str.gsub(/\#\{\s*self([^\}]+?)\s*\}/) do |match|
44
+ str.gsub(/\#\{\s*self([^}]+?)\s*\}/) do |match|
42
45
  path_expr = Regexp.last_match(1)
43
46
  resolve_path(path_expr, labels, match)
44
47
  end
@@ -68,11 +71,9 @@ module IsoDoc
68
71
  end
69
72
 
70
73
  def parse_path(path_expr)
71
- segments = []
72
- path_expr = path_expr.sub(/^\./, "")
73
74
  # Split by dots and brackets while preserving the content
74
- parts = path_expr.scan(/\.?([\w-]+)|\[([^\]]+)\]/)
75
- parts.each do |dot_part, bracket_part|
75
+ parts = path_expr.sub(/^\./, "").scan(/\.?([\w-]+)|\[([^\]]+)\]/)
76
+ parts.each_with_object([]) do |(dot_part, bracket_part), segments|
76
77
  if dot_part
77
78
  segments << dot_part
78
79
  elsif bracket_part
@@ -80,7 +81,6 @@ module IsoDoc
80
81
  segments << segment
81
82
  end
82
83
  end
83
- segments
84
84
  end
85
85
 
86
86
  def normalise_hash(ret)
@@ -123,5 +123,9 @@ module IsoDoc
123
123
  def set(key, val)
124
124
  @labels[key] = val
125
125
  end
126
+
127
+ def merge(new_labels)
128
+ @labels = @labels.deep_merge(new_labels)
129
+ end
126
130
  end
127
131
  end
data/lib/isodoc/i18n.rb CHANGED
@@ -27,7 +27,6 @@ module IsoDoc
27
27
  CJK_SCRIPTS = %w(Hans Hant Jpan Kore).freeze
28
28
 
29
29
  def liquid_init
30
- ::IsoDoc::I18n::Liquid.set(self)
31
30
  ::Liquid::Environment.default.register_filter(::IsoDoc::I18n::Liquid)
32
31
  end
33
32
 
@@ -50,6 +49,7 @@ module IsoDoc
50
49
 
51
50
  # populate with variables, Liquid, inflections, ordinals/spellout
52
51
  def populate(keys, vars = {})
52
+ ::IsoDoc::I18n::Liquid.set(self)
53
53
  ::Liquid::Template.parse(@labels.dig(*Array(keys)))
54
54
  .render(vars.merge("labels" => @labels))
55
55
  end
data/lib/isodoc/l10n.rb CHANGED
@@ -44,15 +44,26 @@ module IsoDoc
44
44
  t = xml.xpath(".//text()").reject { |node| node.text.empty? }
45
45
  text_cache = build_text_cache(t, options[:prev], options[:foll])
46
46
 
47
- # Identify which text nodes are within <esc> tags
48
- esc_indices = Set.new
49
- t.each_with_index do |node, i|
50
- esc_indices.add(i) if node.ancestors("esc").any?
51
- end
47
+ # Find all text nodes within <esc> tags in one XPath query
48
+ # This is O(n) instead of O(n*m) where m is tree depth
49
+ esc_indices = build_esc_indices(xml, t)
52
50
 
53
51
  [t, text_cache, xml, options[:prev], options[:foll], esc_indices]
54
52
  end
55
53
 
54
+ # Build set of indices for text nodes within <esc> tags
55
+ # Handles both namespaced and non-namespaced <esc> elements
56
+ def build_esc_indices(xml, text_nodes)
57
+ # Try both non-namespaced and namespace-agnostic queries
58
+ esc_text_nodes = Set.new(xml.xpath(".//esc//text()") +
59
+ xml.xpath(".//*[local-name()='esc']//text()"))
60
+ Set.new.tap do |indices|
61
+ text_nodes.each_with_index do |node, i|
62
+ indices.add(i) if esc_text_nodes.include?(node)
63
+ end
64
+ end
65
+ end
66
+
56
67
  # Cache text content once per method call to avoid repeated .text calls
57
68
  # Build text cache with optional prepended/appended context
58
69
  # Also, reduce multiple spaces to single, to avoid miscrecognition of space
@@ -57,7 +57,7 @@ module IsoDoc
57
57
  ZH_PUNCT_AUTOTEXT = {
58
58
  colon: ":",
59
59
  comma: ",",
60
- "enum-comma": ",",
60
+ # "enum-comma": ",", # enum-comma is ambiguous with comma
61
61
  semicolon: ";",
62
62
  period: ".",
63
63
  "close-paren": ")",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-13 00:00:00.000000000 Z
11
+ date: 2025-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: canon
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.1.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.1.3
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: debug
99
99
  requirement: !ruby/object:Gem::Requirement