Glossaries support!

LibreTranslate now supports glossaries :partying_face:

This is something that has been asked multiple times in the past and it’s now available with the latest version (1.10.0). To use it, you can pass a glossary object to the request:

curl -X POST -d source=en -d target=it -d q="Hey, you want a Coke?" -d glossary='{"coke":"coca-cola"}' http://localhost:5050/translate
{"translatedText":"Ehi, vuoi una coca-cola?"}

curl -X POST -d source=en -d target=it -d q="Hey, you want a Coke?" -d glossary='{"coke":"coca"}' http://localhost:5050/translate
{"translatedText":"Ehi, vuoi una coca?"}

The biggest challenge was making sure that tagged terms pass through the model correctly and preserving masculine/feminine/plurals. The simple idea of replacing a term with a placeholder (e.g. “Coke” ==> “VZ0”) doesn’t work well with gender/plurals because placeholders (VZ{X}) are almost always interpreted as masculine singular. “VZ” was chosen because it seemed to survive the best across the models.

  • Initially we just try replacing the glossary terms directly in the source language. Most of them make it through unchanged, but with the proper gender and plural form. We double check that every glossary term is accounted for.
  • If this approach didn’t account for some terms, we fallback to placeholders replacement (VZ{X}). We do term accounting on all hypothesis and pick the first one that contains all terms.
  • If this approach fails also, we replace whatever terms made it through.

German and some asian languages have some special handling (for example with German we skip step 1).