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 +4 -4
- data/.idea/i18nize.iml +47 -0
- data/exe/i18nize +17 -0
- data/lib/i18nize/cli.rb +93 -0
- data/lib/i18nize/version.rb +1 -1
- data/lib/tasks/translator.rake +13 -29
- metadata +10 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 78ea8f5bd14b52b8c173e982f375e57ee78a513ac76f814c968eec974de6ece4
|
|
4
|
+
data.tar.gz: f3b3d75ae86ea18979d156774eebae09357cc487e47dd872ed4b2ca68a3bf8be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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)
|
data/lib/i18nize/cli.rb
ADDED
|
@@ -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
|
data/lib/i18nize/version.rb
CHANGED
data/lib/tasks/translator.rake
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "i18nize/
|
|
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
|
-
|
|
10
|
-
abort
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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.
|
|
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:
|
|
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.
|
|
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: []
|