better_translate 0.1.1 → 0.2.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 +4 -4
- data/README.md +30 -16
- data/lib/better_translate/translator.rb +14 -9
- data/lib/better_translate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 861e9d3d1401025d2e12487f5fb6aa4e81cd67b90aa08a0a022d135eb4b71371
|
4
|
+
data.tar.gz: 26ff1894216353f54a8e2f60e9563526ac42da9c9cdc0ae71c4b5bed73c8debc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4082ac26837e5adb8e9b96f2f8738b61219780df6234ce25646f7bcde53faa4848abfb0cb20e0d9063e4ffab789ede5f305ebeb0cf52d7898fb58c67cb68237c
|
7
|
+
data.tar.gz: 66d7e88dbcd40785676ce17168ce177e29a948b7ddc7aa741bca2ed852aeee90fe98e713e28e74b5008da92ad613f6306046fda81be59ac7491b966ef1fcb579
|
data/README.md
CHANGED
@@ -15,15 +15,20 @@ Configuration is centralized via an initializer (for example, in a Rails app), w
|
|
15
15
|
- **Override**: Rewrites the file from scratch.
|
16
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
|
+
- **Two-Step Exclusion Filtering**:
|
19
|
+
- **Global Exclusions**: Removes keys defined in `global_exclusions` from the entire YAML structure.
|
20
|
+
- **Language-Specific Exclusions**: Applies additional filtering using the `exclusions_per_language` map for each target language.
|
18
21
|
- **Progress Bar**: Displays translation progress using ruby-progressbar.
|
19
|
-
- **Generators**:
|
22
|
+
- **Rails Generators**:
|
23
|
+
- `rails generate better_translate:install` to generate the initializer.
|
24
|
+
- `rails generate better_translate:translate` to trigger the translation process directly from your Rails app.
|
20
25
|
|
21
26
|
## Installation
|
22
27
|
|
23
28
|
Add the gem to your Gemfile:
|
24
29
|
|
25
30
|
```ruby
|
26
|
-
gem 'better_translate'
|
31
|
+
gem 'better_translate', '~> 0.1.0'
|
27
32
|
```
|
28
33
|
|
29
34
|
Then run:
|
@@ -76,8 +81,13 @@ BetterTranslate.configure do |config|
|
|
76
81
|
"key.child_key"
|
77
82
|
]
|
78
83
|
|
79
|
-
# Language-specific exclusions
|
84
|
+
# Language-specific exclusions: keys to exclude only for specific target languages
|
80
85
|
config.exclusions_per_language = {
|
86
|
+
"es" => [],
|
87
|
+
"it" => ["sample.valid"],
|
88
|
+
"fr" => [],
|
89
|
+
"de" => [],
|
90
|
+
"pt" => [],
|
81
91
|
"ru" => []
|
82
92
|
}
|
83
93
|
|
@@ -101,19 +111,28 @@ BetterTranslate.magic
|
|
101
111
|
|
102
112
|
This will execute the process that:
|
103
113
|
1. Reads the input YAML file.
|
104
|
-
2. Applies
|
105
|
-
3.
|
106
|
-
4.
|
114
|
+
2. Applies the global exclusion filtering.
|
115
|
+
3. Applies additional language-specific exclusion filtering for each target language.
|
116
|
+
4. Translates the strings from the source language into the configured target languages.
|
117
|
+
5. Writes the translated files to the output folder, either in **override** or **incremental** mode based on the configuration.
|
107
118
|
|
108
119
|
### Using Rails Generators
|
109
120
|
|
110
|
-
The gem includes
|
121
|
+
The gem includes generators to simplify tasks:
|
111
122
|
|
112
|
-
|
113
|
-
|
114
|
-
```
|
123
|
+
- **Generate Initializer:**
|
124
|
+
|
125
|
+
```bash
|
126
|
+
rails generate better_translate:install
|
127
|
+
```
|
128
|
+
|
129
|
+
- **Trigger Translation Process:**
|
115
130
|
|
116
|
-
|
131
|
+
```bash
|
132
|
+
rails generate better_translate:translate
|
133
|
+
```
|
134
|
+
|
135
|
+
The `better_translate:translate` generator will trigger the translation process (via `BetterTranslate.magic`) and display progress in the terminal.
|
117
136
|
|
118
137
|
## Contact & Feature Requests
|
119
138
|
|
@@ -121,7 +140,6 @@ For suggestions, bug reports, or to request new features, please reach out via e
|
|
121
140
|
|
122
141
|
## Upcoming Features
|
123
142
|
|
124
|
-
- **Selective YAML Key Exclusion**: Ability to exclude specific YAML keys for translation on a per-language basis.
|
125
143
|
- **Helper Methods**: Additional helper methods to integrate BetterTranslate as a translation system for dynamic content.
|
126
144
|
|
127
145
|
## Conclusions
|
@@ -130,10 +148,6 @@ BetterTranslate aims to simplify the translation of YAML files in Ruby projects
|
|
130
148
|
|
131
149
|
For more details, please visit the [GitHub repository](https://github.com/alessiobussolari/better_translate).
|
132
150
|
|
133
|
-
## Changelog
|
134
|
-
|
135
|
-
See the [CHANGELOG](https://github.com/alessiobussolari/better_translate/blob/main/CHANGELOG.md) for a summary of changes.
|
136
|
-
|
137
151
|
## License
|
138
152
|
|
139
153
|
BetterTranslate is distributed under the MIT license. See the [LICENSE](LICENSE) file for more details.
|
@@ -7,19 +7,24 @@ module BetterTranslate
|
|
7
7
|
translations = read_yml_source
|
8
8
|
|
9
9
|
# Rimuove le chiavi da escludere (global_exclusions) dalla struttura letta
|
10
|
-
|
10
|
+
global_filtered_translations = remove_exclusions(
|
11
11
|
translations, BetterTranslate.configuration.global_exclusions
|
12
12
|
)
|
13
13
|
|
14
14
|
BetterTranslate.configuration.target_languages.each do |target_lang|
|
15
|
+
|
16
|
+
# Fase 2: Applica il filtro specifico per la lingua target
|
17
|
+
lang_exclusions = BetterTranslate.configuration.exclusions_per_language[target_lang[:short_name]] || []
|
18
|
+
filtered_translations = remove_exclusions(
|
19
|
+
global_filtered_translations, lang_exclusions
|
20
|
+
)
|
21
|
+
|
15
22
|
puts "Inizio traduzione da #{BetterTranslate.configuration.source_language} a #{target_lang[:short_name]}"
|
16
23
|
service = BetterTranslate::Service.new
|
17
24
|
translated_data = translate_with_progress(filtered_translations, service, target_lang[:short_name], target_lang[:name])
|
18
25
|
BetterTranslate::Writer.write_translations(translated_data, target_lang[:short_name])
|
19
26
|
puts "Traduzione completata da #{BetterTranslate.configuration.source_language} a #{target_lang[:short_name]}"
|
20
27
|
end
|
21
|
-
|
22
|
-
"Traduzione iniziata! #{filtered_translations.inspect}"
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
@@ -38,18 +43,18 @@ module BetterTranslate
|
|
38
43
|
YAML.load_file(file_path)
|
39
44
|
end
|
40
45
|
|
41
|
-
# Rimuove le chiavi
|
46
|
+
# Rimuove le chiavi globali da escludere dalla struttura dati,
|
42
47
|
# calcolando i percorsi a partire dal contenuto della lingua di partenza.
|
43
48
|
#
|
44
49
|
# Ad esempio, se il file YAML è:
|
45
|
-
#
|
46
|
-
# e
|
50
|
+
# { "en" => { "sample" => { "valid" => "valid", "excluded" => "Excluded" } } }
|
51
|
+
# e global_exclusions = ["sample.excluded"],
|
47
52
|
# il risultato sarà:
|
48
|
-
#
|
53
|
+
# { "en" => { "sample" => { "valid" => "valid" } } }
|
49
54
|
#
|
50
55
|
# @param data [Hash, Array, Object] La struttura dati da filtrare.
|
51
|
-
# @param
|
52
|
-
# @param current_path [Array] Il percorso corrente (usato in maniera ricorsiva).
|
56
|
+
# @param global_exclusions [Array<String>] Lista dei percorsi (in dot notation) da escludere globalmente.
|
57
|
+
# @param current_path [Array] Il percorso corrente (usato in maniera ricorsiva, default: []).
|
53
58
|
# @return [Hash, Array, Object] La struttura dati filtrata.
|
54
59
|
def remove_exclusions(data, exclusion_list, current_path = [])
|
55
60
|
if data.is_a?(Hash)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alessio_bussolari
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|