Thanks to standardized API interfaces, translation services such as Google Translate or Deepl.com can be used directly with FileMaker to translate texts into other languages. In this short article, we will show you how to create such a translation directly in FileMaker. Interface and thus be able to translate any text.
Both Google Translate and Deepl.com are subject to a fee. One million characters sent to the API cost 20 US dollars and 20 euros respectively for both services, while Deepl.com also charges a monthly basic fee of just under five euros. The translated texts from Deepl.com are generally considered to be slightly better translated than those from Google Translate, although this probably also depends on the subject area. Find out below how an automatic translation of texts in a FileMaker application works.Database can be implemented.
To carry out the translation with Google Translate, a valid Google account is required, which is required to use the Cloud Translation API is activated.
A paid developer account for the DeepL API is required for translation with Deepl.com. The monthly costs are 4.99 euros plus usage-dependent costs (currently 1 cent per 500 characters, as of 03/2019)
FileMaker Crash Course
Fast and effective FileMaker
learning in 20 chapters.
Participate free of charge
Generic Script for the translation
First, we create a script that accepts the source language, target language and the text to be translated via three parameters and sends them to the interface accordingly. In our example, the parameters are separated by line breaks (CR). If you want to send texts with line separators to the interface, use a different separator for the parameters, such as an apostrophe. In this case, do not use the function GetValue ()but another (custom) function that splits the string with your separator. In our example, we call the script "ts.Translate". In the first step, the transferred parameters are each converted into a Variable written.
The script can be called from other scripts as follows:
Execute script [ Specified: From list ; "ts.Translate"; Parameter: ""DE¶EN¶Hello World" ]
Overview of the "ts.Translate" script
Passing the script parameters
Set variable [ $quellsprache ; Value: GetValue(Get(ScriptParameter); 1) ]
Set variable [ $argetLanguage ; Value: GetValue(Get(ScriptParameter); 2) ]
Set variable [ $quelltext ; Value: GetValue(Get(ScriptParameter); 3) ]
The variables 1TP4Source language and $arget language contain the ISO code of the respective language, e.g. DE or EN.
Set variable for the API key
Set variable [ $api_key ; Value: "hJghjjHJHGjkhjKJgÖLkjjjhlkHkjFJKGkjjhlÄf" ]
An authentication key is required to use both the Google Cloud Translation API and the DeepL API. This can be retrieved in the administration area of the respective API.
Call API URL
Google Cloud Translation API
Set variable [ $_url ; Value: "https://www.googleapis.com/language/translate/v2?key=" & $api_key & "&q=" & ReadAsURLEncrypted ($source text) & "&source=" & $source language & "&target=" & $target language ]
DeepL API
Set variable [ $_url ; Value: "https://api.deepl.com/v2/translate?auth_key=" & $api_key & "&source_lang=" & $source_lang & "&target_lang=" & $target_lang & "&text=" & ReadAsURLEncrypted ($source_text) ]
Depending on which provider is to be used, the corresponding script line must be used here. In the variable $_url, the URL that is to be called up for the translation is generated first. The server address is followed by all other values that were saved in the previously defined variables:
- $api_key (Authentication key of the API)
- $source_long (source language as ISO code)
- $target_long (target language as ISO code)
- 1TP4Source text (Passed text, is passed with the function ReadAsURLEncrypted in the URL to avoid sending real line breaks etc.)
Insert from URL [ Selection ; With dialog: Off ; $url_result ; $_url ]
This command calls the URL and saves the result in the variable $url_result.
Read out result and error query
First, the system checks whether the result returned via the URL contains the term "errors". If so, a corresponding error dialog should appear, which contains the variables $_url and $url_result in the text.
When [ PatternNumber ( $url_result ; "errors" ) ]
Display your own dialog box [ "Error occurred" ; $_url & ", " & $url_result ]
Otherwise
Set variable [ $_message_target ; Value:
SetVar ( [
Text = $url_result ;
StartTag = "\"text\":\"" ;
EndTag = "\"}]}" ;
StartPos = Position ( Text ; StartTag ; 1 ; 1 ) ;
StartPos = StartPos + Length ( StartTag ) ;
EndPos = Position ( Text ; EndTag ; StartPos ; 1 ) ;
LengthToKeep = EndPos - StartPos ;
Result = CharacterCenter ( Text ; StartPos ; LengthToKeep ) ] ;
Result & If(PatternNumber(Result; "|") > 0; "|")
)
Filtering of HTML entities
If the returned text contains HTML entities, these can be removed with a Custom Function can be filtered out. In this example, we use the function HTMLencoded2Textwhich is freely available.
When [ PatternNumber ( $_message_target ; "&#" ) ]
Set variable [ $_message_target ; Value: HTMLencoded2Text ( $_message_target ) ]
End (if)
End (if)
Exit script and deliver result
The following command exits the script and returns the result that is displayed in the parent script after execution with the command Get(ScriptResult) can be read out.
Exit current script [ Text result: $_message_target ]
Separation of several text values with a separator
Using the interfaces, it is also possible to assign a separator to several words to be translated in order to enter them later in different variables or fields in a structured manner. With the DeepL API, for example, an apostrophe can easily be used as a separator, while with Google Translate we were able to successfully implement a separator with one or two underscores.

Markus Schall has been developing individual databases, interfaces and business applications based on Claris FileMaker since 1994. He is a Claris partner, FMM Award winner 2011 and developer of the ERP software gFM-Business. He is also a book author and founder of the M. Schall Publishers.


Are there any updates for this? The script cannot be entered like this. I would be very happy about this.
Mfg
Burkhard Quenzler
Hello Burkhard, what exactly can't be entered or what doesn't work? I am not aware that anything has changed technically in the API since then. The StringColumns function corresponds to the "GetValue" function, only with apostrophe as separator.
I tried to type in the script word by word, I think I have a problem with the apostrophe. I'll try again later. Maybe you can send me the ts.Translate script. I would be very grateful.