inertia_i18n 0.3.0 → 0.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: f6aedf82d5304993ab58a1dc1b6f1fedee2bd08328be799da83d0bafd50cba32
4
- data.tar.gz: cfe3ce966e7359e38c3ec0752f4c902735f9f60c79e33b9eac903ef002e41ed0
3
+ metadata.gz: b731d8c8bfdf6ab6f73dceeadc53172e60170786f29922b75f2997dec846cd36
4
+ data.tar.gz: e0ea7396c3b10eb6ed4747e9b1deae9ecaa9e037e1922bbd67241cdf19712534
5
5
  SHA512:
6
- metadata.gz: 249f0dc540b501b336b89a3f69bb32e294a005f510cbfc7ae81c5c1b2c40a40184f046342c2286cbbf561c8eb76d452983a60859b45f066e77db9fffbe745e66
7
- data.tar.gz: cf6145d5310f3162d36dcdcdabdcd9760e8088b5507f874ef6e6b10f97ad8a6584fa17d609e72158f39fd30af4ab9c997f4d310bbfe777cdda6632ae22a7d0fd
6
+ metadata.gz: 664b563f1ca6c78234c7db86849f4bb6da97ced5a21480bd494e3d8177d4a8204f5bc1378eefe58c4e9e398572135409fab80c7ad8c8fbf4010898f6d0bfbd11
7
+ data.tar.gz: ae0cca0e3409bb8665a732d4d4e071c2538f935c1d3bba54349315889b7787ccc96d0d4a5dacef2ef8cf8b15221226f015145d6068eb5e2936910b66ff562fbb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2026-01-28
4
+
5
+ ### Added
6
+
7
+ - `normalize` command now sorts keys in YAML locale files in addition to JSON files
8
+ - `InertiaI18n::Normalizer` class to handle file normalization logic
9
+
3
10
  ## [0.3.0] - 2026-01-19
4
11
 
5
12
  ### Added
@@ -95,22 +95,12 @@ module InertiaI18n
95
95
  exit 1 unless checker.healthy?
96
96
  end
97
97
 
98
- desc "normalize", "Sort and format JSON locale files"
98
+ desc "normalize", "Sort and format YAML and JSON locale files"
99
99
  option :config, type: :string, desc: "Path to config file"
100
100
  def normalize
101
101
  load_config(options[:config])
102
- config = InertiaI18n.configuration
103
-
104
- config.locales.each do |locale|
105
- file = File.join(config.target_path, "#{locale}.json")
106
- next unless File.exist?(file)
107
-
108
- data = JSON.parse(File.read(file))
109
- sorted_data = deep_sort(data)
110
- File.write(file, JSON.pretty_generate(sorted_data) + "\n")
111
102
 
112
- puts "Normalized #{file}"
113
- end
103
+ Normalizer.new.normalize
114
104
  end
115
105
 
116
106
  desc "version", "Show version"
@@ -234,18 +224,5 @@ module InertiaI18n
234
224
  end
235
225
  puts
236
226
  end
237
-
238
- def deep_sort(data)
239
- case data
240
- when Hash
241
- data.keys.sort.each_with_object({}) do |key, sorted|
242
- sorted[key] = deep_sort(data[key])
243
- end
244
- when Array
245
- data.map { |item| deep_sort(item) }
246
- else
247
- data
248
- end
249
- end
250
227
  end
251
228
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "json"
5
+
6
+ module InertiaI18n
7
+ class Normalizer
8
+ def normalize
9
+ normalize_json_files
10
+ normalize_yaml_files
11
+ end
12
+
13
+ private
14
+
15
+ def normalize_json_files
16
+ config = InertiaI18n.configuration
17
+
18
+ config.locales.each do |locale|
19
+ file = File.join(config.target_path, "#{locale}.json")
20
+ next unless File.exist?(file)
21
+
22
+ data = JSON.parse(File.read(file))
23
+ sorted_data = deep_sort(data)
24
+ File.write(file, JSON.pretty_generate(sorted_data) + "\n")
25
+
26
+ puts "Normalized #{file}"
27
+ end
28
+ end
29
+
30
+ def normalize_yaml_files
31
+ config = InertiaI18n.configuration
32
+
33
+ yaml_files = config.source_paths.flat_map do |path|
34
+ Dir.glob(File.join(path, config.source_pattern))
35
+ end.uniq
36
+
37
+ yaml_files.each do |file|
38
+ next unless File.exist?(file)
39
+
40
+ begin
41
+ data = YAML.load_file(file, permitted_classes: [Symbol])
42
+ next unless data
43
+
44
+ sorted_data = deep_sort(data)
45
+
46
+ File.write(file, sorted_data.to_yaml)
47
+ puts "Normalized #{file}"
48
+ rescue Psych::SyntaxError => e
49
+ warn "Warning: Failed to parse #{file}: #{e.message}"
50
+ end
51
+ end
52
+ end
53
+
54
+ def deep_sort(data)
55
+ case data
56
+ when Hash
57
+ data.keys.sort.each_with_object({}) do |key, sorted|
58
+ sorted[key] = deep_sort(data[key])
59
+ end
60
+ when Array
61
+ data.map { |item| deep_sort(item) }
62
+ else
63
+ data
64
+ end
65
+ end
66
+ end
67
+ end
@@ -25,7 +25,7 @@ namespace :inertia_i18n do
25
25
  InertiaI18n::Cli.new.health
26
26
  end
27
27
 
28
- desc "Sort and format JSON locale files"
28
+ desc "Sort and format YAML and JSON locale files"
29
29
  task normalize: :environment do
30
30
  require "inertia_i18n/cli"
31
31
  InertiaI18n::Cli.new.normalize
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InertiaI18n
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/inertia_i18n.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "inertia_i18n/parsers/vue_parser"
12
12
  require_relative "inertia_i18n/scanner"
13
13
  require_relative "inertia_i18n/locale_loader"
14
14
  require_relative "inertia_i18n/file_converter"
15
+ require_relative "inertia_i18n/normalizer"
15
16
  require_relative "inertia_i18n/health_checker"
16
17
  require_relative "inertia_i18n/railtie" if defined?(Rails::Railtie)
17
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Poimtsev
@@ -162,6 +162,7 @@ files:
162
162
  - lib/inertia_i18n/file_converter.rb
163
163
  - lib/inertia_i18n/health_checker.rb
164
164
  - lib/inertia_i18n/locale_loader.rb
165
+ - lib/inertia_i18n/normalizer.rb
165
166
  - lib/inertia_i18n/parsers/base_parser.rb
166
167
  - lib/inertia_i18n/parsers/javascript_parser.rb
167
168
  - lib/inertia_i18n/parsers/javascript_parsing.rb