A reader from Germany recently thanked me for making the FileMaker to Google 2D Barcode example file and requested a similar demo of having FileMaker work with Google Translate. I took up the challenge, because I wish this functionality was built into things like Facebook (so I can understand my German, French and Danish friends when they post in their own languages), and figured that others might find this functionality useful in FileMaker.
It turned out to be a fairly simple integration, but requires users to sign up for their own Google API Key. Like many Google services these days, Translate is not free and there are no Courtesy Limit, so you start paying right away by the character. Pricing seems reasonable at low levels of usage. The full Google Translate API documentation is available here.
Download the FileMaker Google Translate Demo here.
Once you have obtained a Google Translate API Key (you need to give them a current credit card for it to be functional), you can paste the API Key string into the FileMaker global settings field in the demo called, strangely, Google API Key.
Make sure the preferred method of translation is set to the Google API method. The Google Web Browser approach will open your default browser with your translation in a browser. This approach appears to be free and does not require an API key but does requires you cut and paste the result back into your database.
How to Translate text from a FileMaker field.
1) Enter the Language From
2) Select the Language To
3) Enter some text
4) Click Translate button
5) Translated Text
The main script in action here is one called “Translate Text – API Method”.
The basics are:
1) A test to see if you have an API key entered
2) Send a calculated URL to a named Web Viewer (Language FROM, Language TO and Text To Translate)
3) Wait for a response from the Web Viewer
4) Test for ‘error’ in the result – display the error message and halt script. The Google error is usually pretty descriptive and should help you solve the issue.
5) Parse a positive result into the Translated Text field using a Custom Function called ParseData
6) Reset the Web Viewer
The Calculated URL step
This is the step that sends a calculated URL to the named Web Viewer. These variables are coming from text fields in the database.
- Google API Key
- Text To Translate
- Language FROM
- Language TO
Custom Function: ParseData
In File: Manage: Custom Functions, I have added a Custom Function called ParseData. I got this from www.briandunning.com, a web site that maintains a good collection of Custom Functions. This Custom Function helps to parse out the translated text from the source code that is returned from the Google Translate web service.
Limitation to the Length of Text to be Translated
Because this method is sending the text to Google Translate in the URL string, there are obviously going to be a limitations on the length of what can be sent. While there does not appear to be a set limit, different browsers have different limits.
Bonus Points: What if you don’t know the language you are starting from?
There appears to be a method in the Google Translate API of just sending text to the Translate engine and letting it figure out what language the text is in. I did not try this, but it may be an area others want to develop. If you improve on the demo, I encourage you to send me your changes and I can add them to the basic demo I have created.
Getting Help about FileMaker – FAST!
Where Am I? Using FileMaker Go 12 to track your Location
Creating Google Cluster Maps from FileMaker
Creating and Storing 2D Bar Codes in FileMaker