better_translate 0.1.0 → 0.1.1
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/README.md +43 -20
- data/lib/better_translate/version.rb +1 -1
- data/lib/generators/better_translate/translate_generator.rb +15 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39116f70ea2683daa65f22e5acad342e91010465dc76b00046a34f3f369b471b
|
4
|
+
data.tar.gz: d2687a9e7ab0867894b56ae4563715aa06b61d7071755ef337f86d80fe72dfbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41e2a36c986088a37612c72d692a2ca89e9fa6b5c52951f7b5a3e41201820baa49aa362213670d1f1d52c3735afb2e06bad94dcea640fdc35fe88c3e90a2d468
|
7
|
+
data.tar.gz: 35035a09d3f7088739ecc0b8cc46ef9e7863a546dbeaf2809ce6ef611417933fd30950ed226d297a770d38fda7c4d04e31e5a3be6219ebd7a89301739261a1d9
|
data/README.md
CHANGED
@@ -3,19 +3,20 @@
|
|
3
3
|
BetterTranslate is a Ruby gem that enables you to translate YAML files from a source language into one or more target languages using translation providers such as ChatGPT (OpenAI) and Google Gemini. The gem supports two translation modes:
|
4
4
|
|
5
5
|
- **Override**: Completely rewrites the translated file.
|
6
|
-
- **Incremental**: Updates the translated file only with new or modified keys while keeping existing ones.
|
6
|
+
- **Incremental**: Updates the translated file only with new or modified keys while keeping the existing ones.
|
7
7
|
|
8
8
|
Configuration is centralized via an initializer (for example, in a Rails app), where you can set API keys, the source language, target languages, key exclusions, the output folder, and the translation mode. Additionally, BetterTranslate integrates progress tracking using the [ruby-progressbar](https://github.com/jfelchner/ruby-progressbar) gem.
|
9
9
|
|
10
10
|
## Features
|
11
11
|
|
12
12
|
- **Multi-language YAML Translation**: Translates YAML files from a source language into one or more target languages.
|
13
|
-
- **Multiple Providers**: Supports ChatGPT (OpenAI) and Google Gemini (with potential for
|
14
|
-
- **Translation Modes**:
|
15
|
-
|
16
|
-
|
13
|
+
- **Multiple Providers**: Supports ChatGPT (OpenAI) and Google Gemini (with potential for extension to other providers in the future).
|
14
|
+
- **Translation Modes**:
|
15
|
+
- **Override**: Rewrites the file from scratch.
|
16
|
+
- **Incremental**: Updates only missing or modified keys.
|
17
17
|
- **Centralized Configuration**: Configured via an initializer with settings for API keys, source language, target languages, exclusions (using dot notation), and the output folder.
|
18
|
-
- **Progress Bar**: Displays
|
18
|
+
- **Progress Bar**: Displays translation progress using ruby-progressbar.
|
19
|
+
- **Generators**: Includes Rails generators to easily install the initializer and to trigger the translation process (e.g., via `rails generate better_translate:translate`).
|
19
20
|
|
20
21
|
## Installation
|
21
22
|
|
@@ -23,6 +24,7 @@ Add the gem to your Gemfile:
|
|
23
24
|
|
24
25
|
```ruby
|
25
26
|
gem 'better_translate'
|
27
|
+
```
|
26
28
|
|
27
29
|
Then run:
|
28
30
|
|
@@ -50,38 +52,38 @@ This command creates the file `config/initializers/better_translate.rb` with a d
|
|
50
52
|
BetterTranslate.configure do |config|
|
51
53
|
# Choose the provider to use: :chatgpt or :gemini
|
52
54
|
config.provider = :chatgpt
|
53
|
-
|
55
|
+
|
54
56
|
# API key for ChatGPT (OpenAI)
|
55
57
|
config.openai_key = ENV.fetch("OPENAI_API_KEY") { "YOUR_OPENAI_API_KEY" }
|
56
|
-
|
58
|
+
|
57
59
|
# API key for Google Gemini
|
58
60
|
config.google_gemini_key = ENV.fetch("GOOGLE_GEMINI_KEY") { "YOUR_GOOGLE_GEMINI_KEY" }
|
59
|
-
|
61
|
+
|
60
62
|
# Source language (e.g., "en" if the source file is in English)
|
61
63
|
config.source_language = "en"
|
62
|
-
|
64
|
+
|
63
65
|
# Output folder where the translated files will be saved
|
64
66
|
config.output_folder = Rails.root.join("config", "locales", "translated").to_s
|
65
|
-
|
67
|
+
|
66
68
|
# List of target languages (short_name and name)
|
67
69
|
config.target_languages = [
|
68
70
|
# Example:
|
69
71
|
{ short_name: "it", name: "italian" }
|
70
72
|
]
|
71
|
-
|
73
|
+
|
72
74
|
# Global exclusions (keys in dot notation) to exclude from translation
|
73
75
|
config.global_exclusions = [
|
74
|
-
"key.child_key"
|
76
|
+
"key.child_key"
|
75
77
|
]
|
76
|
-
|
78
|
+
|
77
79
|
# Language-specific exclusions (optional)
|
78
80
|
config.exclusions_per_language = {
|
79
81
|
"ru" => []
|
80
82
|
}
|
81
|
-
|
83
|
+
|
82
84
|
# Path to the input file (e.g., en.yml)
|
83
85
|
config.input_file = Rails.root.join("config", "locales", "en.yml").to_s
|
84
|
-
|
86
|
+
|
85
87
|
# Translation mode: :override or :incremental
|
86
88
|
config.translation_method = :override
|
87
89
|
end
|
@@ -89,7 +91,7 @@ end
|
|
89
91
|
|
90
92
|
## Usage
|
91
93
|
|
92
|
-
### YAML
|
94
|
+
### Translating YAML Files
|
93
95
|
|
94
96
|
To start the translation process, simply call the `magic` method:
|
95
97
|
|
@@ -100,12 +102,33 @@ BetterTranslate.magic
|
|
100
102
|
This will execute the process that:
|
101
103
|
1. Reads the input YAML file.
|
102
104
|
2. Applies any filters (exclusions).
|
103
|
-
3. Translates the strings from the source language
|
105
|
+
3. Translates the strings from the source language into the configured target languages.
|
104
106
|
4. Writes the translated files to the output folder, either in **override** or **incremental** mode based on the configuration.
|
105
107
|
|
106
|
-
|
108
|
+
### Using Rails Generators
|
109
|
+
|
110
|
+
The gem includes a generator to trigger the translation process. You can run:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
rails generate better_translate:translate
|
114
|
+
```
|
115
|
+
|
116
|
+
This generator will call the translation process (via `BetterTranslate.magic`) and display the progress in the terminal.
|
117
|
+
|
118
|
+
## Contact & Feature Requests
|
119
|
+
|
120
|
+
For suggestions, bug reports, or to request new features, please reach out via email at: **alessio.bussolari@pandev.it**.
|
121
|
+
|
122
|
+
## Upcoming Features
|
123
|
+
|
124
|
+
- **Selective YAML Key Exclusion**: Ability to exclude specific YAML keys for translation on a per-language basis.
|
125
|
+
- **Helper Methods**: Additional helper methods to integrate BetterTranslate as a translation system for dynamic content.
|
126
|
+
|
127
|
+
## Conclusions
|
128
|
+
|
129
|
+
BetterTranslate aims to simplify the translation of YAML files in Ruby projects by providing a flexible, configurable, and extensible system. Whether you need a complete file rewrite or an incremental update, BetterTranslate streamlines the translation process using advanced providers like ChatGPT and Google Gemini. Contributions, feedback, and feature requests are highly encouraged to help improve the gem further.
|
107
130
|
|
108
|
-
|
131
|
+
For more details, please visit the [GitHub repository](https://github.com/alessiobussolari/better_translate).
|
109
132
|
|
110
133
|
## Changelog
|
111
134
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module BetterTranslate
|
4
|
+
module Generators
|
5
|
+
class TranslateGenerator < Rails::Generators::Base
|
6
|
+
desc "Lancia il processo di traduzione configurato in BetterTranslate"
|
7
|
+
|
8
|
+
def run_translation
|
9
|
+
say_status("Starting", "Esecuzione della traduzione con BetterTranslate...", :green)
|
10
|
+
BetterTranslate.magic
|
11
|
+
say_status("Done", "Traduzione completata.", :green)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alessio_bussolari
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/better_translate/writer.rb
|
108
108
|
- lib/generators/better_translate/install_generator.rb
|
109
109
|
- lib/generators/better_translate/templates/better_translate.rb
|
110
|
+
- lib/generators/better_translate/translate_generator.rb
|
110
111
|
homepage: https://github.com/alessiobussolari/better_translate
|
111
112
|
licenses:
|
112
113
|
- MIT
|