logo elektroda
logo elektroda
X
logo elektroda

Automatic text translation in Google Sheets (Excel online). Let's translate firmware.

p.kaczmarek2  Cool? (+7)
📢 Listen (AI):
Google Sheets columns with translations to various languages .
Google Sheets offer a wide range of features, here I will focus on one of them - the GOOGLETRANSLATE function. This function allows us to automatically translate words and phrases between two languages, just like regular Google Translate, but its presence in the sheet can really save us a lot of time. In this particular case, I will demonstrate the translation of a potential home automation firmware, but I think it has many more applications and there is something for everyone.


Basics of GOOGLETRANSLATE
Open our Google sheet and type in A1 some example word - "Relay":

Google Sheet with the word Przekaźnik entered in cell A1 .
.
In B1 type the equals sign and then start typing GOOGLE, a hint should already appear:
GOOGLETRANSLATE function suggestion in Google Sheets .
.
Validate, now three arguments need to be entered:
GOOGLETRANSLATE formula in Google Sheets .
.
The arguments are:
- text to be translated (or a cell with it)
- source language
- target language
Done:
Google Sheet with GOOGLETRANSLATE formula translating the word Przekaźnik. .
.
Everything works:
Google Sheet with translation function from Polish to English


We are expanding the sheet .
We already know how GOOGLETRANSLATE works, but it's time to start using it better. First a small change - in my firmware everything is in English, so the base language will be English. Apart from that, I'll throw out the language codes written "hard" in the cells so that they are in the first cell. So we are looking into the language codes:
https://developers.google.com/admin-sdk/directory/v1/languages?hl=pl
We create columns for each of them:
Screenshot of a Google Sheet with technical translations in various languages. .
.
We enter the magic formula. The whole idea here is to use the character $ to enable absolute addressing for column A (source word), for the source language and for the target language row:
Screenshot of Google Sheets showing the use of the GOOGLETRANSLATE function to translate the word Relay from English to Polish. .
.
Mark cell and stretch downwards:
Google Sheets snippet with GOOGLETRANSLATE function. .
.
And then to the right:
Google Sheets columns with translations to various languages .


Related feature .
While we're on the subject of translations, it's worth mentioning a related function, namely DetectLanguage - this returns the language code for a given word:
Screenshot of a Google Sheet using the DETECTLANGUAGE function to identify the language of the word Achtung. .
Thus we get:
Google Sheets cell with the word Achtung and language code de .
Can be useful if you do not recognise the language in question.

Potential pitfall
Is everything now perfectly translated? Unfortunately not, rather someone familiar with the language should review it. Google Translate isn't perfect and doesn't know the context, so strange translations still happen. Rather, what we have done should only be a base for further translations.


Export results .
Now it is a matter of further processing the data. A CSV file, or comma separated values, can be downloaded from Google Sheets.
Screenshot of the download menu in Google Sheets showing the CSV option selection. .
.
This is how the file looks after downloading:
Simple CSV file with technical translations into various languages
.
The structure of the file is really very simple. It can be loaded very easily in your own program, two steps are enough:
- reading it line by line
- divide the line into phrases according to commas
Example code in C#:
Code: C#
Log in, to see the code
.
This code simply reads in such a file and extracts separate values from it. The loading is carried out line by line.

How is the translation implemented for programs written in C/C++? .
It's time to go one step further and think about how we can make language versions for our software. Let's look at some practical example here, how is this done in Tasmota for example?
https://tasmota.github.io/docs/
To start with, there can be two ways of translations:
- a language version embedded at compile time in the firmware (only one, selected) - this requires changing the batch to change the language, but saves memory
- you can also keep different language versions in the batch (or load them from files, etc.) - this takes more memory
Tasmota has separate binary files for the languages:
Tasmota installation options with a dropdown language selection menu..
.
The translation is implemented using a preprocessor:
Screenshot of defined macros for different messages in a Tasmota header file. .
.
We have separate headers that define the subtitles, e.g:
Code: C / C++
Log in, to see the code
.
Here are some of them:
List of language translation files for Tasmota
.
For German:
Screenshot of the Tasmota header file in German, containing preprocessor definitions with translations. .
.
And then in the application code the simply executed #define is used, like this:
Code: C / C++
Log in, to see the code
.
It is important to note that only one of these headers is included at compile time. Then compilation is performed separately for each such header and the result is separate binaries, one file per language.


Automatic header generation .
Now that we know how translations are implemented by Tasmota, let's try to map the same in our code. Let's add the names of the preprocessor definitions to our sheet:
Google Sheet with translations of words into various languages. .
.
Next, let's modify our code so that it automatically reads the CSV and creates translation headers:
Code: C#
Log in, to see the code
.
It's worth remembering that I start the loops here with 1 rather than 0, to skip the first name column for the preprocessor. I create separate files for each language in turn:
List of C++ header files in the translations folder .
The files so far are very simple:
C preprocessor code defining words like Relay and Button. .
.
Here it would still be useful to make some kind of standard, instead of just NO, maybe better S_NO, etc. As in Tasmota, by the way, they have a D_ prefix there.
So we change:
Code: C#
Log in, to see the code
.
to:
Code: C#
Log in, to see the code
.
Of course, this is just a seed and there are still a few potential things to improve with this, but for demonstration purposes this will suffice.

Summary
Undoubtedly Google Sheets can help with translation automation, including when translating a program to a microcontroller, although I still think some care needs to be taken when doing this and running any translation through someone who knows the language. In addition, it is worth remembering that the adventure does not end with the Sheets alone, because you can always download the CSV and process it further, even if only in simple self-written programmes, as I have also shown here..
And what uses do you have for Google Sheets? Feel free to discuss.

About Author
p.kaczmarek2
p.kaczmarek2 wrote 12319 posts with rating 10206 , helped 583 times. Been with us since 2014 year.

Comments

Pawel_ 24 Jul 2024 12:24

Nonetheless, one would also have to check the quality of the translations themselves because, looking at the context, the word 'Current' should be translated as 'Current' and not 'Current'. [Read more]

p.kaczmarek2 24 Jul 2024 14:04

Congratulations, watchful eye, I wondered if anyone would see it, but I also included a warning about it in the text in the paragraph "Potential pitfall". Anyway, it wouldn't be the first time, how... [Read more]

TechEkspert 24 Jul 2024 15:26

An interesting mechanism, however, in this way and without correction, unfortunately, Chinese translations of the GUI and instructions are most likely to be produced.... [Read more]

krzbor 24 Jul 2024 23:53

@ElektrodaBot In the picture below are translations of technical phrases from English into Polish, Czech, German and Russian respectively. Are these translations correct? https://obrazki.elektroda... [Read more]

ElektrodaBot 24 Jul 2024 23:55

1. Relay: - en: Relay - en: Relay - cs: Relé - de: Relais - ru: Реле The translations are correct. 2: Button: - en: Button - en: Button - cs: Knoflík - de: Taste - ru:... [Read more]

krzbor 25 Jul 2024 00:01

Quite a good analysis. How about using ChatGPT instead of Google translator? [Read more]

TechEkspert 25 Jul 2024 09:32

GPT has beaten google, I wonder if it will replace the search engine and translator in the future. [Read more]

krzbor 26 Jul 2024 10:28

This is almost certain to happen. Here is an example - Google translation of the words: trunc, extension, phone into Polish: cut off, extension, phone Chat command: Translate to Polish: trunc, extension,... [Read more]

Urgon 26 Jul 2024 11:16

AVE... I am currently correcting translations of articles from Dutch to Polish for EdW (sometimes I also write my own articles). Some professional machine-learning-based programme is used for the translation,... [Read more]

divadiow 29 Jul 2024 20:42

That's brilliant Added after 4 [minutes]: Is this thread a preamble to making OpenBeken available in other languages? [Read more]

p.kaczmarek2 29 Jul 2024 21:10

Maybe we need to take another approach and make a single call to OpenAI GPT API with request to "detect the context and translate". It may be better than Google. [Read more]

krzbor 01 Aug 2024 20:02

. We will try: @ElectrodBot Translate the following technical phrases (related to electricity) from English into Polish, Czech, German and Russian. Save the result as JSON. Relay, Button, Voltage,... [Read more]

ElektrodaBot 01 Aug 2024 20:05

{ "Relay": { "pl": "Przekaźnik", "cs": "Relé", "de": "Relais", "ru": "Реле" }, "Button": { "pl": "Przycisk", "cs": "Tlačítko", "de": "Taste", "ru": "Кнопка" }, ... [Read more]

krzbor 01 Aug 2024 20:07

I think it worked out pretty well? [Read more]

p.kaczmarek2 01 Aug 2024 20:15

You did it a bit differently @krzbor than I assumed. I was thinking not to prompt in the prompt what the phrases are related to, but to write a prompt like (preferably in English) "Translate the phrases... [Read more]

p.kaczmarek2 14 Aug 2024 10:22

. An elaboration of the idea can be found in this topic: Translation of concepts by AI while preserving context - ChatGPT prompt and beyond [Read more]

%}