mistral_translator 0.5.0 → 0.6.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/CHANGELOG.md +19 -0
- data/README.md +10 -1
- data/docs/api-reference/configuration.md +2 -2
- data/docs/api-reference/errors.md +6 -6
- data/docs/api-reference/methods.md +2 -2
- data/docs/getting-started.md +10 -6
- data/lib/mistral_translator/data/languages.json +2367 -0
- data/lib/mistral_translator/data/regions.json +1170 -0
- data/lib/mistral_translator/data/scripts.json +182 -0
- data/lib/mistral_translator/helpers.rb +5 -5
- data/lib/mistral_translator/locale.rb +84 -0
- data/lib/mistral_translator/locale_helper.rb +14 -29
- data/lib/mistral_translator/translator_helpers.rb +4 -3
- data/lib/mistral_translator/version.rb +1 -1
- data/lib/mistral_translator.rb +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b22420512964b68bed142cf6a3321456342be0e2cfb20296250786b054307642
|
|
4
|
+
data.tar.gz: 9c2e3ae8f96a65bd331ed3e81f47c22a064ef8141dc43327f5e76c1322d79ffa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9eeb4e98442dfb7fff7a4549794e15186387733ff7a07eb9c5bc6c3a9464de02f417433477317e305b90055e1140c537a5312cdb9c1c5c4c4525b981e7c86bc6
|
|
7
|
+
data.tar.gz: 761772d205f97f680c6efaf3dff60953e62f62e995394a79bc9a284a27aceaca5c522271d139744aad49ca5f75d8549b5f13b05f421211374c9bfd313cb23373
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [0.6.0] - 2026-11-17
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- 437 languages that only have an ISO 639-3 code (`haw`, `yue`, `fil`…), 619 in all. The ISO 639-3 code of a two-letter language is accepted in its place (`hat` for `ht`).
|
|
6
|
+
- Scripts and regions: `pt-BR`, `zh-Hant-TW`, `es-419`, any combination of the scripts and regions CLDR names. The prompt names the variant, such as « portugais (Brésil) (pt-BR) ».
|
|
7
|
+
- `MistralTranslator::Locale`, a value object that reads a locale (`Locale.parse`, or `Locale.find`, which returns `nil` instead of raising) and gives its canonical form (`to_s`).
|
|
8
|
+
- Language names work wherever a locale is expected: `translate(text, from: "fr", to: "allemand")`. They only worked in locale suggestions. A name several languages share, such as "konkani", is rejected: use the code.
|
|
9
|
+
- `bin/generate_languages` also writes `scripts.json` and `regions.json`.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
Only regional locales and locales with extensions are affected; two-letter codes behave as before.
|
|
14
|
+
|
|
15
|
+
- A locale keeps its region. `translate_to_multiple(text, from: "en", to: ["pt-BR"])` returns `{ "pt-BR" => … }` instead of `{ "pt" => … }`, and `validate_locale!("pt-BR")` returns `"pt-BR"` instead of `"pt"`. Before, `pt-BR` and `pt-PT` in the same call overwrote each other.
|
|
16
|
+
- Two variants of a language are no longer the same locale: from `fr` to `fr-CA`, the text is translated by the API instead of being returned unchanged. A Rails app with `fr` and `fr-CA` locales now gets an adapted translation, for one more request.
|
|
17
|
+
- Variants and extensions (`ca-ES-valencia`, `en-US-u-ca-gregory`) raise `UnsupportedLanguageError`. Their subtags used to be dropped silently, leaving the language only.
|
|
18
|
+
- `locale_supported?` returns `true` for language names, which `translate` now accepts.
|
|
19
|
+
|
|
1
20
|
## [0.5.0] - 2026-10-29
|
|
2
21
|
|
|
3
22
|
### Added
|
data/README.md
CHANGED
|
@@ -37,7 +37,16 @@ MistralTranslator.translate("Bonjour le monde", from: "fr", to: "en")
|
|
|
37
37
|
|
|
38
38
|
## Supported Languages
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Every language CLDR names, 619 in all: the 182 ISO 639-1 languages (`fr`, `en`, `ja`, `ht`, `wo`…) and the languages that only have an ISO 639-3 code (`haw`, `yue`, `fil`…). `MistralTranslator.supported_locales` lists them.
|
|
41
|
+
|
|
42
|
+
A locale can add a script and a region (`pt-BR`, `zh-Hant-TW`, `es-419`): the model is told which variant to write, and results are keyed by that locale. ISO 639-3 codes (`hat` for `ht`) and English, French or native names (`"German"`, `"allemand"`) are accepted in place of codes. Variants and extensions (`ca-ES-valencia`, `en-US-u-ca-gregory`) are not.
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
MistralTranslator.translate(text, from: "fr", to: "pt-BR")
|
|
46
|
+
MistralTranslator::Locale.parse("zh_hant_tw").to_s # => "zh-Hant-TW"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The languages, scripts and regions come from the CLDR data of macOS 27.2, through `bin/generate_languages` (2026-11-17).
|
|
41
50
|
|
|
42
51
|
Translation quality depends on the Mistral model: excellent for widely used languages, weaker for rare ones. Check the output before relying on a rare language.
|
|
43
52
|
|
|
@@ -103,9 +103,9 @@ config.setup_rails_logging # Active les logs Rails standard
|
|
|
103
103
|
MistralTranslator.health_check
|
|
104
104
|
# => { status: :ok, message: "API connection successful" }
|
|
105
105
|
|
|
106
|
-
# Langues supportées :
|
|
106
|
+
# Langues supportées : 619 codes ISO 639-1 et ISO 639-3
|
|
107
107
|
MistralTranslator.supported_locales
|
|
108
|
-
# => ["aa", "ab", "
|
|
108
|
+
# => ["aa", "ab", "ace", "acf", ..., "zun", "zza"]
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
---
|
|
@@ -290,21 +290,21 @@ puts result # => "" (sans erreur)
|
|
|
290
290
|
|
|
291
291
|
```ruby
|
|
292
292
|
MistralTranslator.supported_locales
|
|
293
|
-
# => ["
|
|
293
|
+
# => ["aa", "ab", "ace", "acf", ..., "zun", "zza"] (619 langues)
|
|
294
294
|
```
|
|
295
295
|
|
|
296
296
|
**Exemple:**
|
|
297
297
|
|
|
298
298
|
```ruby
|
|
299
299
|
begin
|
|
300
|
-
MistralTranslator.translate("Hello", from: "en", to: "
|
|
300
|
+
MistralTranslator.translate("Hello", from: "en", to: "dothraki")
|
|
301
301
|
rescue MistralTranslator::UnsupportedLanguageError => e
|
|
302
302
|
puts "Unsupported language: #{e.message}"
|
|
303
303
|
puts "Language requested: #{e.language}"
|
|
304
|
-
# => "
|
|
304
|
+
# => "dothraki"
|
|
305
305
|
|
|
306
306
|
# Obtenir des suggestions :
|
|
307
|
-
suggestions = MistralTranslator::Helpers.validate_locale_with_suggestions("
|
|
307
|
+
suggestions = MistralTranslator::Helpers.validate_locale_with_suggestions("dothraki")
|
|
308
308
|
if suggestions[:suggestions].any?
|
|
309
309
|
puts "Did you mean: #{suggestions[:suggestions].join(', ')}?"
|
|
310
310
|
end
|
|
@@ -315,7 +315,7 @@ end
|
|
|
315
315
|
|
|
316
316
|
- Utiliser `MistralTranslator.supported_locales` pour voir les langues disponibles
|
|
317
317
|
- Utiliser le helper de validation avec suggestions
|
|
318
|
-
-
|
|
318
|
+
- Vérifier le code : `"pt-BR"`, `"zh-Hant"`, `"haw"` ou un nom comme `"allemand"` sont acceptés ; les variantes et extensions BCP 47 (`"ca-ES-valencia"`) ne le sont pas
|
|
319
319
|
|
|
320
320
|
---
|
|
321
321
|
|
|
@@ -647,7 +647,7 @@ describe "error handling" do
|
|
|
647
647
|
it "provides fallback for unsupported languages" do
|
|
648
648
|
result = translate_with_fallback(
|
|
649
649
|
"Hello",
|
|
650
|
-
from: "
|
|
650
|
+
from: "dothraki",
|
|
651
651
|
to: "fr",
|
|
652
652
|
fallback: "Hello"
|
|
653
653
|
)
|
|
@@ -298,7 +298,7 @@ Remet la configuration aux valeurs par défaut.
|
|
|
298
298
|
|
|
299
299
|
Retourne la liste des codes de langue supportés.
|
|
300
300
|
|
|
301
|
-
**Retour:** Array<String> -
|
|
301
|
+
**Retour:** Array<String> - Les 619 codes de langue, ISO 639-1 et ISO 639-3 (ex: ["aa", "ab", "ace", ..., "zza"]). Une locale peut y ajouter une écriture et une région (`"zh-Hant-TW"`).
|
|
302
302
|
|
|
303
303
|
### `supported_languages`
|
|
304
304
|
|
|
@@ -467,7 +467,7 @@ Validation de locale avec suggestions.
|
|
|
467
467
|
**Retour:** Hash
|
|
468
468
|
|
|
469
469
|
- `valid` (Boolean) - Locale valide ou non
|
|
470
|
-
- `locale` (String) - Locale
|
|
470
|
+
- `locale` (String) - Locale canonique, région comprise (ex: `"pt-BR"`), si valide
|
|
471
471
|
- `suggestions` (Array) - Suggestions (si invalide)
|
|
472
472
|
|
|
473
473
|
##### `estimate_translation_cost(text, from:, to:, rate_per_1k_chars:)`
|
data/docs/getting-started.md
CHANGED
|
@@ -39,20 +39,24 @@ MistralTranslator.translate_auto("Guten Tag", to: "fr")
|
|
|
39
39
|
## 🌍 Langues Supportées
|
|
40
40
|
|
|
41
41
|
```ruby
|
|
42
|
-
#
|
|
42
|
+
# 619 langues : codes ISO 639-1 (deux lettres) et ISO 639-3 (trois lettres)
|
|
43
43
|
MistralTranslator::LocaleHelper.supported_locales
|
|
44
|
-
# => ["aa", "ab", "
|
|
44
|
+
# => ["aa", "ab", "ace", "acf", ..., "zun", "zza"]
|
|
45
45
|
|
|
46
|
-
#
|
|
47
|
-
MistralTranslator
|
|
48
|
-
|
|
46
|
+
# Une écriture et une région précisent la variante
|
|
47
|
+
MistralTranslator.translate("Bonjour", from: "fr", to: "pt-BR")
|
|
48
|
+
MistralTranslator.translate("Bonjour", from: "fr", to: "zh-Hant-TW")
|
|
49
|
+
|
|
50
|
+
# Les noms de langue et les codes ISO 639-3 sont acceptés à la place du code
|
|
51
|
+
MistralTranslator::Locale.parse("allemand").to_s # => "de"
|
|
52
|
+
MistralTranslator::Locale.parse("hat").to_s # => "ht"
|
|
49
53
|
|
|
50
54
|
# Vérifier une langue spécifique
|
|
51
55
|
MistralTranslator::LocaleHelper.locale_supported?("ja")
|
|
52
56
|
# => true
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
Les langues, écritures et régions viennent des données CLDR de macOS 27.2, via `bin/generate_languages` (2026-11-17). Les variantes et extensions BCP 47 (`ca-ES-valencia`, `en-US-u-ca-gregory`) ne sont pas acceptées.
|
|
56
60
|
|
|
57
61
|
La qualité de traduction dépend du modèle Mistral : excellente pour les langues les plus parlées, plus faible pour les langues rares. Vérifiez le résultat avant de vous appuyer sur une langue rare.
|
|
58
62
|
|