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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b02e4c378ffdd992bbb525c57a03fd15c4c82e2ee916c43a3753b09398c8e0
4
- data.tar.gz: 1bdf19928ac211fbbc7e7fe064f600d53639c3b0aa57063b14b74fe3b95384c0
3
+ metadata.gz: b22420512964b68bed142cf6a3321456342be0e2cfb20296250786b054307642
4
+ data.tar.gz: 9c2e3ae8f96a65bd331ed3e81f47c22a064ef8141dc43327f5e76c1322d79ffa
5
5
  SHA512:
6
- metadata.gz: 67bb96d4142aa345f2feb2f1cf35ef30e131d529ad22338e9bd31c0c237d165a446b74e8ed75aa7715d903e486657250fb823e4add5994edade18d763fa50e2f
7
- data.tar.gz: 39fcfd92f88aa10bb1ca930a8c9539a9d3e12ce7a8b4d1564d2cd0336ac5f349d9903334abec4a7f0d8fe8876a90d82738d8e6bc2a024bc91df5303c8f096588
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
- All 182 ISO 639-1 languages named by CLDR (`fr`, `en`, `es`, `de`, `ja`, `br`, `wo`, `mg`…). `MistralTranslator.supported_locales` lists them, and English or French names are accepted in place of codes (`"German"`, `"allemand"`). The list and the names come from the CLDR data of macOS 27.2, through `bin/generate_languages` (2026-10-28).
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 : les 182 codes ISO 639-1
106
+ # Langues supportées : 619 codes ISO 639-1 et ISO 639-3
107
107
  MistralTranslator.supported_locales
108
- # => ["aa", "ab", "ae", "af", ..., "zh", "zu"]
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
- # => ["fr", "en", "es", "pt", "de", "it", "nl", "ru", "mg", "ja", "ko", "zh", "ar"]
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: "klingon")
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
- # => "klingon"
304
+ # => "dothraki"
305
305
 
306
306
  # Obtenir des suggestions :
307
- suggestions = MistralTranslator::Helpers.validate_locale_with_suggestions("klingon")
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
- - Normaliser les codes de langue (ex: "français" → "fr")
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: "klingon",
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> - Liste des 182 codes ISO 639-1 (ex: ["aa", "ab", ..., "zu"])
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 normalisée (si valide)
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:)`
@@ -39,20 +39,24 @@ MistralTranslator.translate_auto("Guten Tag", to: "fr")
39
39
  ## 🌍 Langues Supportées
40
40
 
41
41
  ```ruby
42
- # Les 182 langues ISO 639-1 sont disponibles
42
+ # 619 langues : codes ISO 639-1 (deux lettres) et ISO 639-3 (trois lettres)
43
43
  MistralTranslator::LocaleHelper.supported_locales
44
- # => ["aa", "ab", "ae", "af", ..., "zh", "zu"]
44
+ # => ["aa", "ab", "ace", "acf", ..., "zun", "zza"]
45
45
 
46
- # Les noms anglais et français sont acceptés à la place du code
47
- MistralTranslator::LocaleHelper.language_to_locale("allemand")
48
- # => "de"
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
- La liste et les noms viennent des données CLDR de macOS 27.2, via `bin/generate_languages` (2026-10-28).
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