i18nize 0.4.0 → 0.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: 1bbc7b819de676a9785ce3b8232d5e9890203f24edec51f424d282e07ca22e0b
4
- data.tar.gz: 9b74128b649ac289886290dcd53e972e0f54dc3c0e78c86787d5a9d071484334
3
+ metadata.gz: 78ea8f5bd14b52b8c173e982f375e57ee78a513ac76f814c968eec974de6ece4
4
+ data.tar.gz: f3b3d75ae86ea18979d156774eebae09357cc487e47dd872ed4b2ca68a3bf8be
5
5
  SHA512:
6
- metadata.gz: 6d296327d3a75d4f39d0290cee254747a6162939e4c03480a10dfec9de1554d14b270303f2cc1076580205ad657a88a997d345aec88c3dc4517a4e6cc56d33fd
7
- data.tar.gz: 8acdfcf17abca4dd3aa93dfb8ba43174db1c80cd420f43df6861456762609a4036795e88a874d589bcad1a1009a849972837653ecb5990725e85093356cb86a1
6
+ metadata.gz: bb64139a19f726fda950ccd7a3148872509e2991d061e95ec741008e68152619a564041b46eda3387d762df691739e7ddaba3f55a35267c41083d23f1700364f
7
+ data.tar.gz: 54c6ed5bc10f790bd0bf99cbdd4d439a6d77764d8c5ff7c9e435c1d28b8381fc29456c8e11287b7bbcbdce59cf42daddf18d6a95fac1e13b1e6cbc775dce0979
data/.idea/i18nize.iml CHANGED
@@ -3,4 +3,51 @@
3
3
  <component name="ModuleRunConfigurationManager">
4
4
  <shared />
5
5
  </component>
6
+ <component name="RakeTasksCache-v2">
7
+ <option name="myRootTask">
8
+ <RakeTaskImpl id="rake">
9
+ <subtasks>
10
+ <RakeTaskImpl description="Build i18nize-0.4.0.gem into the pkg directory" fullCommand="build" id="build" />
11
+ <RakeTaskImpl id="build">
12
+ <subtasks>
13
+ <RakeTaskImpl description="Generate SHA512 checksum of i18nize-0.4.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
14
+ </subtasks>
15
+ </RakeTaskImpl>
16
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
17
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
18
+ <RakeTaskImpl id="i18nize">
19
+ <subtasks>
20
+ <RakeTaskImpl description="Auto-translate missing I18n keys using DeepL (usage: rake 'i18nize:translate[cs]')" fullCommand="i18nize:translate[to_locale]" id="translate[to_locale]" />
21
+ <RakeTaskImpl description="" fullCommand="i18nize:translate" id="translate" />
22
+ </subtasks>
23
+ </RakeTaskImpl>
24
+ <RakeTaskImpl description="Build and install i18nize-0.4.0.gem into system gems" fullCommand="install" id="install" />
25
+ <RakeTaskImpl id="install">
26
+ <subtasks>
27
+ <RakeTaskImpl description="Build and install i18nize-0.4.0.gem into system gems without network access" fullCommand="install:local" id="local" />
28
+ </subtasks>
29
+ </RakeTaskImpl>
30
+ <RakeTaskImpl description="Create tag v0.4.0 and build and push i18nize-0.4.0.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
31
+ <RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
32
+ <RakeTaskImpl id="rubocop">
33
+ <subtasks>
34
+ <RakeTaskImpl description="Autocorrect RuboCop offenses (only when it's safe)" fullCommand="rubocop:autocorrect" id="autocorrect" />
35
+ <RakeTaskImpl description="Autocorrect RuboCop offenses (safe and unsafe)" fullCommand="rubocop:autocorrect_all" id="autocorrect_all" />
36
+ <RakeTaskImpl description="" fullCommand="rubocop:auto_correct" id="auto_correct" />
37
+ </subtasks>
38
+ </RakeTaskImpl>
39
+ <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
40
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
41
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
42
+ <RakeTaskImpl id="release">
43
+ <subtasks>
44
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
45
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
46
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
47
+ </subtasks>
48
+ </RakeTaskImpl>
49
+ </subtasks>
50
+ </RakeTaskImpl>
51
+ </option>
52
+ </component>
6
53
  </module>
data/exe/i18nize ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ begin
5
+ require "bundler/setup"
6
+ rescue LoadError
7
+ # Ignore
8
+ end
9
+
10
+ begin
11
+ require "dotenv/load"
12
+ rescue LoadError
13
+ # Ignore
14
+ end
15
+
16
+ require "i18nize/cli"
17
+ exit I18nize::CLI.run(ARGV)
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+
5
+ module I18nize
6
+ class CLI
7
+ def self.run(argv)
8
+ new(argv).run
9
+ end
10
+
11
+ def initialize(argv)
12
+ @argv = argv.dup
13
+ @options = { from: "en" }
14
+ end
15
+
16
+ def run
17
+ print_help_and_exit if @argv.empty? || help_requested?
18
+
19
+ to_locale = parse_positional_locale!(@argv.first)
20
+ parse_flags!(@argv[1..] || [])
21
+
22
+ api_key = ENV["DEEPL_API_KEY"]
23
+ abort red("Missing DEEPL_API_KEY env variable") if api_key.to_s.strip.empty?
24
+
25
+ load_rails_if_available
26
+
27
+ puts cyan("Starting translation: from #{@options[:from]} → #{to_locale}")
28
+
29
+ translator = I18nize::Translator.new(
30
+ auth_key: api_key,
31
+ from_lang: @options[:from].upcase,
32
+ to_lang: to_locale.upcase
33
+ )
34
+
35
+ I18nize::Inserter.insert_missing(
36
+ to_locale: to_locale,
37
+ translator: translator
38
+ )
39
+
40
+ puts green("✅ Translation completed.")
41
+ 0
42
+ end
43
+
44
+ private
45
+
46
+ def help_requested?
47
+ (@argv & %w[-h --help help]).any?
48
+ end
49
+
50
+ def parse_positional_locale!(arg)
51
+ abort yellow("Usage: i18nize <to_locale> [--from en]") unless arg
52
+ arg.strip
53
+ end
54
+
55
+ def parse_flags!(rest)
56
+ OptionParser.new do |o|
57
+ o.banner = "Usage: i18nize <to_locale> [options]"
58
+ o.on("--from LANG", "Source language (default: en)") { |v| @options[:from] = v }
59
+ o.on("-h", "--help", "Show help") { print_help_and_exit }
60
+ end.parse!(rest)
61
+ end
62
+
63
+ def load_rails_if_available
64
+ return if defined?(Rails)
65
+
66
+ require_relative "../../config/environment" if File.exist?("config/environment.rb")
67
+ rescue LoadError
68
+ # Ignore
69
+ end
70
+
71
+ def print_help_and_exit
72
+ puts <<~HELP
73
+ Usage:
74
+ i18nize <to_locale> [--from en]
75
+
76
+ Examples:
77
+ i18nize cs
78
+ i18nize fr --from en
79
+ HELP
80
+ exit 0
81
+ end
82
+
83
+ def color(text, code) = "\e[#{code}m#{text}\e[0m"
84
+
85
+ def red(text) = color(text, 31)
86
+
87
+ def green(text) = color(text, 32)
88
+
89
+ def yellow(text) = color(text, 33)
90
+
91
+ def cyan(text) = color(text, 36)
92
+ end
93
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nize
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.2"
5
5
  end
@@ -1,36 +1,20 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
- require "i18nize/inserter"
4
- require "i18nize/translator"
3
+ require "i18nize/cli"
5
4
 
6
5
  namespace :i18nize do
7
- desc "Auto-translate missing I18n keys using DeepL"
6
+ desc "Auto-translate missing I18n keys using DeepL (usage: rake 'i18nize:translate[cs]')"
8
7
  task :translate, [:to_locale] do |_, args|
9
- api_key = ENV["DEEPL_API_KEY"]
10
- abort red("Missing DEEPL_API_KEY env variable") unless api_key
11
-
12
- to_locale = args[:to_locale]
13
- abort yellow("Usage: rake i18nize:translate[cs]") unless to_locale
14
-
15
- puts cyan("Starting translation to '#{to_locale}'...")
16
-
17
- translator = I18nize::Translator.new(
18
- auth_key: api_key,
19
- from_lang: "EN",
20
- to_lang: to_locale.upcase
21
- )
22
-
23
- I18nize::Inserter.insert_missing(
24
- to_locale: to_locale,
25
- translator: translator
26
- )
27
-
28
- puts green("✅ Translation completed.")
8
+ to = args[:to_locale]
9
+ abort "Usage: rake 'i18nize:translate[cs]'" unless to
10
+ I18nize::CLI.run([to] + env_flags_from_rake)
29
11
  end
12
+ end
30
13
 
31
- def color(text, code); "\e[#{code}m#{text}\e[0m"; end
32
- def red(text) = color(text, 31)
33
- def green(text) = color(text, 32)
34
- def yellow(text) = color(text, 33)
35
- def cyan(text) = color(text, 36)
14
+ def env_flags_from_rake
15
+ flags = []
16
+ flags += ["--from", ENV["SOURCE"]] if ENV["SOURCE"]
17
+ flags
36
18
  end
19
+
20
+ def truthy?(v) = %w[1 true yes y on].include?(v.to_s.downcase)
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18nize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nikolas2145
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2025-09-08 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: ''
13
14
  email:
14
15
  - nikolas2145@gmail.com
15
- executables: []
16
+ executables:
17
+ - i18nize
16
18
  extensions: []
17
19
  extra_rdoc_files: []
18
20
  files:
@@ -28,7 +30,9 @@ files:
28
30
  - LICENSE.txt
29
31
  - README.md
30
32
  - Rakefile
33
+ - exe/i18nize
31
34
  - lib/i18nize.rb
35
+ - lib/i18nize/cli.rb
32
36
  - lib/i18nize/comparer.rb
33
37
  - lib/i18nize/inserter.rb
34
38
  - lib/i18nize/loader.rb
@@ -45,6 +49,7 @@ metadata:
45
49
  homepage_uri: https://github.com/nikolas2145/i18nize
46
50
  source_code_uri: https://github.com/nikolas2145/i18nize
47
51
  changelog_uri: https://github.com/nikolas2145/i18nize/blob/main/CHANGELOG.md
52
+ post_install_message:
48
53
  rdoc_options: []
49
54
  require_paths:
50
55
  - lib
@@ -59,7 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
64
  - !ruby/object:Gem::Version
60
65
  version: '0'
61
66
  requirements: []
62
- rubygems_version: 3.6.9
67
+ rubygems_version: 3.4.19
68
+ signing_key:
63
69
  specification_version: 4
64
70
  summary: Auto-translates missing I18n keys in YAML files using DeepL.
65
71
  test_files: []