site  contact  subhomenews

Started developing automatic language translation

January 06, 2023 — BarryK

The folder for this new project is /usr/local/translation, and the first script is 'translate-string'.
It will read a sentence in English, from /tmp/translate-shell/en-input-string, the script is called passing the target language on the commandline, for example:

# /usr/local/translate/translate-string fr

And the translated sentence will be in /tmp/translate-shell/translated-output-string. For example, here is English input and French output:

The EasyOS operating system has now released version ${VER} and this is great, download from http://from.here.com/subdir.
Le système d’exploitation EasyOS a maintenant publié la version ${VER} et c’est génial, télécharger depuis http://from.here.com/subdir.

The trick in the script is that it forces certain strings to not be translated. In the above example, that is "EasyOS", "${VER}" and "http://from.here.com/subdir"

The method used to exclude certain strings is by means of a list of regular expressions, in file /usr/local/translate/keep-patterns. Strings that are not to be translated are converted to an untranslatable string by use of 'base32' utility.

I posted about using 'base32' in the Puppy Forum:

https://forum.puppylinux.com/viewtopic.php?t=7736

The script uses 'translate-shell', project page:

https://github.com/soimort/translate-shell

...which can use different translation engines. The default is "google"; however, I found that "bing" does a better job. The google engine was limiting translation to 178 characters -- searched online, could nowhere find that limit mentioned. OK, I'm using it for free, and there is a daily limit I think, so maybe that's it. Maybe I hit the daily limit and it truncated my translation to only 178 characters.    

Tags: easy