i18nize 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1bbc7b819de676a9785ce3b8232d5e9890203f24edec51f424d282e07ca22e0b
4
+ data.tar.gz: 9b74128b649ac289886290dcd53e972e0f54dc3c0e78c86787d5a9d071484334
5
+ SHA512:
6
+ metadata.gz: 6d296327d3a75d4f39d0290cee254747a6162939e4c03480a10dfec9de1554d14b270303f2cc1076580205ad657a88a997d345aec88c3dc4517a4e6cc56d33fd
7
+ data.tar.gz: 8acdfcf17abca4dd3aa93dfb8ba43174db1c80cd420f43df6861456762609a4036795e88a874d589bcad1a1009a849972837653ecb5990725e85093356cb86a1
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GitToolBoxProjectSettings">
4
+ <option name="commitMessageIssueKeyValidationOverride">
5
+ <BoolValueOverride>
6
+ <option name="enabled" value="true" />
7
+ </BoolValueOverride>
8
+ </option>
9
+ <option name="commitMessageValidationEnabledOverride">
10
+ <BoolValueOverride>
11
+ <option name="enabled" value="true" />
12
+ </BoolValueOverride>
13
+ </option>
14
+ </component>
15
+ </project>
data/.idea/i18nize.iml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ </module>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="MaterialThemeProjectNewConfig">
4
+ <option name="metadata">
5
+ <MTProjectMetadataState>
6
+ <option name="migrated" value="true" />
7
+ <option name="pristineConfig" value="false" />
8
+ <option name="userId" value="-151e60b4:18eb353ec10:-7ffc" />
9
+ </MTProjectMetadataState>
10
+ </option>
11
+ </component>
12
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-30
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 nikolas2145
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # i18nize
2
+
3
+ 🧠 Automatically fills in missing I18n YAML keys using DeepL translation API.
4
+ Designed to streamline multi-language support in Ruby and Rails projects.
5
+
6
+
7
+ ## ✨ Features
8
+
9
+ - Detects missing or empty translation keys in locale files
10
+ - Supports multiple YAML files and nested directories (e.g. `config/locales/api/en.yml`)
11
+ - Automatically translates from a source locale (default: `en`) to a target (e.g. `cs`)
12
+ - Integrates with DeepL API (Free or Pro)
13
+ - Safely merges translations into corresponding `*.yml` files
14
+ - Includes character count check with confirmation
15
+ - CLI via Rake task
16
+
17
+
18
+ ## 🔧 Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem "i18nize"
24
+ ````
25
+
26
+ Then run:
27
+
28
+ ```bash
29
+ bundle install
30
+ ```
31
+
32
+ Or install manually:
33
+
34
+ ```bash
35
+ gem install i18nize
36
+ ```
37
+
38
+
39
+ ## 🚀 Usage
40
+
41
+ ### 1. Set your DeepL API key
42
+
43
+ Create a `.env` or export it in your shell:
44
+
45
+ ```bash
46
+ export DEEPL_API_KEY=your-api-key
47
+ export DEEPL_ENDPOINT=https://api.deepl.com/v2/translate # Only if you are using a DeepL Pro account
48
+ ```
49
+
50
+ > You can use the [Free DeepL API](https://www.deepl.com/pro#developer)
51
+
52
+
53
+
54
+ ### 2. Run the translation task
55
+
56
+ ```bash
57
+ bundle exec rake "i18nize:translate[language]"
58
+ ```
59
+
60
+ 💬 This will:
61
+
62
+ * Scan config/locales/**/*en.yml (English is the default source language)
63
+ * Detect which `language.yml` files are missing keys
64
+ * Use DeepL to translate missing values
65
+ * Write them to the appropriate files (e.g. `config/locales/errors/language.yml`)
66
+
67
+
68
+
69
+ ## 🛡️ Character limit check
70
+
71
+ Before translating, the task will:
72
+
73
+ * Count the total number of characters to be translated
74
+ * Warn if the count exceeds **500,000** (DeepL Free monthly limit)
75
+ * Ask for confirmation:
76
+
77
+ ```text
78
+ [i18nize] Estimated character count: 43125
79
+ Proceed with translation? [y/N]:
80
+ ```
81
+
82
+
83
+
84
+ ## 🗂️ Locale file support
85
+
86
+ * Files are grouped per folder and matched:
87
+
88
+ * `config/locales/api/en.yml` → `config/locales/api/cs.yml`
89
+ * `config/locales/en.devise.yml` → `config/locales/cs.devise.yml`
90
+ * Missing files are created automatically
91
+
92
+
93
+
94
+ ## 🧩 Example structure
95
+
96
+ ```
97
+ config/locales/
98
+ ├── api/
99
+ │ └── en.yml
100
+ ├── errors/
101
+ │ ├── en.yml
102
+ │ └── cs.yml
103
+ ```
104
+
105
+ After running `rake i18nize:translate[cs]`, the gem will create:
106
+
107
+ ```
108
+ config/locales/api/cs.yml
109
+ ```
110
+
111
+ With keys translated from `api/en.yml`.
112
+
113
+ ---
114
+
115
+ ## 📦 Configuration
116
+
117
+ For now, configuration is via method arguments and `ENV["DEEPL_API_KEY"]`.
118
+ Optional future support: `.i18nize.yml`.
119
+
120
+
121
+
122
+ ## 🔍 TODO
123
+
124
+ * Test suite (RSpec)
125
+ * YAML key sorting and format preservation
126
+ * Smart overwrite protection
127
+ * Changeable source language
128
+
129
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # Rakefile
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/gem_tasks"
5
+
6
+ $LOAD_PATH.unshift File.expand_path("lib", __dir__)
7
+
8
+ begin
9
+ require "rspec/core/rake_task"
10
+ RSpec::Core::RakeTask.new(:spec)
11
+ rescue LoadError
12
+ skip
13
+ end
14
+
15
+ begin
16
+ require "rubocop/rake_task"
17
+ RuboCop::RakeTask.new(:rubocop)
18
+ rescue LoadError
19
+ skip
20
+ end
21
+
22
+ Dir.glob("lib/tasks/**/*.rake").sort.each { |f| import f }
23
+
24
+ task default: [:spec]
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "loader"
4
+ require_relative "missing_set"
5
+
6
+ module I18nize
7
+ class Comparer
8
+ def self.missing_translations(from_locale: "en", to_locale:)
9
+ from_data = Loader.load_per_file(locale: from_locale)
10
+ to_data = Loader.load_per_file(locale: to_locale)
11
+
12
+ result = {}
13
+
14
+ from_data.each do |from_path, from_keys|
15
+ dirname = File.dirname(from_path)
16
+ filename = File.basename(from_path)
17
+ expected_to_filename = filename.sub(/^#{from_locale}\.yml$/, "#{to_locale}.yml")
18
+ to_path = File.join(dirname, expected_to_filename)
19
+
20
+ to_keys = to_data[to_path] || {}
21
+
22
+ missing = from_keys.select do |key, _|
23
+ to_key = key.sub(/^#{from_locale}\./, "#{to_locale}.")
24
+ !to_keys.key?(to_key)
25
+ end
26
+
27
+ result[from_path] = missing unless missing.empty?
28
+ end
29
+
30
+ MissingSet.new(from_locale: from_locale, to_locale: to_locale, data: result)
31
+ end
32
+
33
+ def self.missing_keys(from_locale: "en", to_locale:)
34
+ missing_translations(from_locale: from_locale, to_locale: to_locale).keys_by_file
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "fileutils"
5
+ require_relative "comparer"
6
+
7
+ module I18nize
8
+ class Inserter
9
+ def self.insert_missing(from_locale: "en", to_locale:, base_path: "config/locales", translator: nil)
10
+ missing_data = Comparer.missing_translations(from_locale: from_locale, to_locale: to_locale)
11
+
12
+ if translator
13
+ char_count = missing_data.character_count
14
+ puts "\n\e[33m[i18nize] Estimated character count: #{char_count}\e[0m"
15
+
16
+ if char_count > 500_000
17
+ puts "\e[31m[i18nize] Warning: DeepL Free has a 500,000 character monthly limit.\e[0m"
18
+ end
19
+
20
+ print "\e[36mProceed with translation? [y/N]: \e[0m"
21
+ answer = $stdin.gets.strip.downcase
22
+
23
+ unless answer == "y"
24
+ puts "\e[90m[i18nize] Aborted by user.\e[0m"
25
+ return
26
+ end
27
+ end
28
+
29
+ missing_data.data.each do |from_rel_path, translations|
30
+ dirname = File.dirname(from_rel_path)
31
+ filename = File.basename(from_rel_path)
32
+
33
+ new_filename = filename.sub(/^#{from_locale}\.yml$/, "#{to_locale}.yml")
34
+ to_rel_path = File.join(dirname, new_filename)
35
+ to_full_path = File.join(base_path, to_rel_path)
36
+
37
+ existing = File.exist?(to_full_path) ? YAML.load_file(to_full_path) : {}
38
+ existing[to_locale] ||= {}
39
+
40
+ translation_map =
41
+ if translator
42
+ en_values = translations.values
43
+ translated_values = translator.translate_texts(en_values)
44
+ translations.keys.zip(translated_values.values).to_h
45
+ else
46
+ translations
47
+ end
48
+
49
+ translation_map.each do |key, value|
50
+ path = key.sub(/^#{from_locale}\./, "").split(".")
51
+ insert_nested(existing[to_locale], path, value)
52
+ end
53
+
54
+ FileUtils.mkdir_p(File.dirname(to_full_path))
55
+ File.write(to_full_path, existing.to_yaml(line_width: -1))
56
+
57
+ puts "\e[32m[i18nize] Inserted #{translation_map.size} keys into #{to_full_path}\e[0m"
58
+ end
59
+ end
60
+
61
+ def self.insert_nested(base, keys, value)
62
+ key = keys.shift
63
+ base[key] ||= {}
64
+
65
+ if keys.empty?
66
+ base[key] = value
67
+ else
68
+ insert_nested(base[key], keys, value)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module I18nize
6
+ class Loader
7
+ def self.load_per_file(locale: "en", base_path: "config/locales")
8
+ files = Dir.glob(File.join(base_path, "**", "*.yml")).select do |f|
9
+ filename = File.basename(f)
10
+ filename =~ /(^|[\._])#{Regexp.escape(locale)}\.yml$/
11
+ end
12
+
13
+ files.each_with_object({}) do |file_path, result|
14
+ data = load_file(file_path, locale)
15
+ relative_path = file_path.start_with?(base_path) ? file_path.sub(/^#{Regexp.escape(base_path)}\//, "") : file_path
16
+ result[relative_path] = data unless data.empty?
17
+ end
18
+ end
19
+
20
+ def self.load_flat_keys(locale: "en", base_path: "config/locales")
21
+ load_per_file(locale: locale, base_path: base_path).values.reduce({}) { |acc, h| acc.merge(h) }
22
+ end
23
+
24
+ def self.load_file(file_path, expected_locale)
25
+ raw = YAML.load_file(file_path)
26
+
27
+ # Some files may contain multiple top-level locales, we only care about the expected one
28
+ raw = raw.transform_keys(&:to_s)
29
+ return {} unless raw.key?(expected_locale.to_s)
30
+
31
+ flatten_hash(raw[expected_locale.to_s]).transform_keys { |k| "#{expected_locale}.#{k}" }
32
+ rescue Psych::SyntaxError => e
33
+ warn "[i18nize] Skipping file with YAML error: #{file_path} (#{e.message})"
34
+ {}
35
+ end
36
+
37
+ private
38
+
39
+ def self.flatten_hash(hash, prefix = "")
40
+ hash.each_with_object({}) do |(key, value), flat|
41
+ full_key = prefix.empty? ? key.to_s : "#{prefix}.#{key}"
42
+ if value.is_a?(Hash)
43
+ flat.merge!(flatten_hash(value, full_key))
44
+ else
45
+ flat[full_key] = value
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module I18nize
4
+ require "byebug"
5
+ class MissingSet
6
+ attr_reader :from_locale, :to_locale, :data
7
+
8
+ def initialize(from_locale:, to_locale:, data:)
9
+ @from_locale = from_locale
10
+ @to_locale = to_locale
11
+ @data = data # hash: { file => { key => value } }
12
+ end
13
+
14
+ def empty?
15
+ data.empty?
16
+ end
17
+
18
+ def total_keys
19
+ data.values.map(&:keys).flatten.size
20
+ end
21
+
22
+ def character_count
23
+ data.values.flat_map(&:values).join.length
24
+ end
25
+
26
+ def keys_by_file
27
+ data.transform_values(&:keys)
28
+ end
29
+
30
+ def values_by_file
31
+ data
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "uri"
5
+ require "json"
6
+
7
+ module I18nize
8
+ class Translator
9
+ ENDPOINT = ENV.fetch("DEEPL_ENDPOINT", "https://api-free.deepl.com/v2/translate")
10
+
11
+ def initialize(auth_key:, from_lang: "EN", to_lang:)
12
+ @auth_key = auth_key
13
+ @from_lang = from_lang
14
+ @to_lang = to_lang
15
+ end
16
+
17
+ def translate_texts(texts)
18
+ return {} if texts.empty?
19
+
20
+ uri = URI(ENDPOINT)
21
+
22
+ # Opakující se text parametry
23
+ body_params = [
24
+ ["auth_key", @auth_key],
25
+ ["source_lang", @from_lang],
26
+ ["target_lang", @to_lang],
27
+ ] + texts.map { |text| ["text", text] }
28
+
29
+ request = Net::HTTP::Post.new(uri)
30
+ request["Content-Type"] = "application/x-www-form-urlencoded"
31
+ request.body = URI.encode_www_form(body_params)
32
+
33
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
34
+ http.request(request)
35
+ end
36
+
37
+ unless response.is_a?(Net::HTTPSuccess)
38
+ raise "DeepL API Error: #{response.code} - #{response.body}"
39
+ end
40
+
41
+ json = JSON.parse(response.body)
42
+ translated = json["translations"].map { |t| t["text"] }
43
+
44
+ Hash[texts.zip(translated)]
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module I18nize
4
+ VERSION = "0.4.0"
5
+ end
data/lib/i18nize.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "i18nize/version"
4
+
5
+ module I18nize
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: false
2
+
3
+ require "i18nize/inserter"
4
+ require "i18nize/translator"
5
+
6
+ namespace :i18nize do
7
+ desc "Auto-translate missing I18n keys using DeepL"
8
+ 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.")
29
+ end
30
+
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)
36
+ end
data/sig/i18nize.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module I18nize
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18nize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - nikolas2145
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: ''
13
+ email:
14
+ - nikolas2145@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".idea/.gitignore"
20
+ - ".idea/git_toolbox_prj.xml"
21
+ - ".idea/i18nize.iml"
22
+ - ".idea/material_theme_project_new.xml"
23
+ - ".idea/vcs.xml"
24
+ - ".rspec"
25
+ - ".rubocop.yml"
26
+ - CHANGELOG.md
27
+ - CODE_OF_CONDUCT.md
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - lib/i18nize.rb
32
+ - lib/i18nize/comparer.rb
33
+ - lib/i18nize/inserter.rb
34
+ - lib/i18nize/loader.rb
35
+ - lib/i18nize/missing_set.rb
36
+ - lib/i18nize/translator.rb
37
+ - lib/i18nize/version.rb
38
+ - lib/tasks/translator.rake
39
+ - sig/i18nize.rbs
40
+ homepage: https://github.com/nikolas2145/i18nize
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ allowed_push_host: https://rubygems.org
45
+ homepage_uri: https://github.com/nikolas2145/i18nize
46
+ source_code_uri: https://github.com/nikolas2145/i18nize
47
+ changelog_uri: https://github.com/nikolas2145/i18nize/blob/main/CHANGELOG.md
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.1.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.6.9
63
+ specification_version: 4
64
+ summary: Auto-translates missing I18n keys in YAML files using DeepL.
65
+ test_files: []