As you all know, starting from 2022 we started using artificial intelligence for translations on our platform- [Platform: the set of the main domain and all the subdomain of a particular website; also the computer architecture and equipment using a particular operating system] - (which can also be activated for free as an extension for any network or content). Today I want to delve into the open-source machine translation software- [Program/Software: the instructions that control what a computer does; computer programs] - used for this process as well as the whole process to create your artificial neural network- [Network of Contents: is the channel in which owners can post their content and the audience can see the contents posted by the owners] - .
The software used is called “Libre Translate” and is developed thanks to a vast network of open-source developers around the world who also take care of its maintenance; since it is an open-source software, it is advisable to use it on operating systems such as Linux (it can also work on other systems but for this document we will focus on the use on Linux and Debian, Ubuntu). I also remind you that as long as you use software installed on your systems, these are completely free both in use and resources (obviously the more you use them, the more energy and computing power is needed); you can, however, offer your users the use of a key for the API with restrictions. In this post we will focus only on the use of this translation system for internal translation of texts and resources, and not for the sale of any automatic translations to your users (to do this it is advisable to use the online systems at the site libretranslate.com). Furthermore, this software can be used with a variety of languages such as: rust, nodejs, typescript, .net, go, python, php, c++, swift, unix, shell, java, ruby, r; in this document we will limit ourselves to the PHP programming language for the web.
First of all you need to install python on your operating system, if you haven’t already done so:
sudo apt update
sudo apt install python3
Then you need to install the libre translate software via python:
pip install libretranslate
Once installed, you can now start the software like this:
libretranslate [args]
Remember to do this every time your computer starts, if you need the translation software to be always ready; you can use a cronjob or a .sh file to make sure that at every reboot of the computer, the software is already active without having to start it manually every time.
At this point the software is already usable, only locally, by accessing this address via the system browser:
http://localhost:5000
But this is just the beginning, because we have to use the software through our custom interface that will take care of:
1) Install a library, for example in php, to use it in a project in that code
2) Detect the language used by the user and make the variable available in ISO 639-2 codes, possibly also through a database
3) Build the translation query
4) save the translation in a database as a cache (to be more performing when the same translation is requested)
To make your life easier you can use one of the already built PHP libraries like this one (with code examples): https://github.com/jefs42/libretranslate
At this point you will need to call the library in your project and then translate your first sentence:
// use locally installed LibreTranslate server on port 5000 with default language settings
$translator = new LibreTranslate();
// specifally request languages to use in translation.
// eg. from English to Italian
$translatedText = $translator->translate("Welcome on MYETV dear user", "en", "it");
echo $translatedText;
The variable $translatedText will be the one that will contain the text already translated; following the examples it is also possible to translate entire files or add any options to customize the translation. When building a complete artificial intelligence, it is advisable to export the translation performed on a database so that next time, performing the exact same translation, the $translatedText variable will be taken directly from the database without weighing on the system performance (this system is called caching); furthermore, it is also advisable to make the input language to be translated (for example “en”) and the output language to be translated (for example “it”) variable, also taking these two variables from a database that can be filtered by the language currently used by the user (the language selection can also be done manually through a select box).
The use of complex artificial intelligence also depends on how the entire translation platform is structured through the use of variables, databases, and end-user language recognition systems; by saving the translation in databases, it will also be possible in the future to be able to modify the translation manually through a process built ad hoc. The output variable is differentiated based on these inputs given to the software. Also remember that the software contains translation models that need to be updated from time to time.
Using whole file translation it is also possible, for example, to translate .vtt files, which are video content- [Contents: every content intended as text, images, audio or video] - transcription files automatically generated during the conversion of video files. I will talk about artificial intelligence regarding written transcription of videos in a future post.
Libre translate is a software Made by LibreTranslate Contributors and powered by Argos Translate