A service is to be created that delivers the corresponding string in another language for a string in one language, provided that the external translation API used for this purpose supports the languages:
- There shall be an implementation for the integration of DeepL.
- Since there is a cost per translated character:
- they are counted and limited by the service,
- the API key is not provided,
- the service is disabled by default.
In addition to the service there are:
- (one) Debug Configuration to translate a given *.properties file
- (one) Ant task to translate all *.properties files(for now, in the src/META-INF folder)
In case of abort in the middle of the file, both mechanisms save the already translated lines.
Configuration
Turn on the service in the *.config.xml of the application: {{#!xml <config service-class="com.top_logic.basic.module.ModuleSystem"> <instance>
<modules>
<module key="com.top_logic.basic.translation.TranslationService$Module" value="true" />
</modules>
</instance> </config> }}
Configuration of the connection (here in the example of DeepL): {{#!xml <config service-class="com.top_logic.basic.translation.TranslationService"> <instance class="com.top_logic.basic.translation.DeepLTranslationService"
api-host="https://api.deepl.com/v2/translate"
api-key="%TRANSLATION_API_KEY%"
max-accumulated-translation-size="2500"
max-request-size="30k"
split-sentences="nonewlines"
tag-handling="xml"
/> </config> }} See also tl:DeepLTranslationService
Note the following about the individual parameters:
- api-key: internally, the configuration has access to the alias %TRANSLATION_API_KEY%, so you don't need to change anything. For the application, an API key must be obtained from DeepL and *encrypted* in the alias in the application configuration:
{{#!xml <alias> <entry name="%TRANSLATION_API_KEY%" value="..." /> </alias> }}
- max-accumulated-translation-size is the upper bound of translatable characters. The counter is set to 0 at application startup and is reset every night from then on.
API
Call one of the translate methods{{#!java TranslationService.getInstance().translate(...); }}} Cf. tl:TranslationService
Test
The TestDeepLTranslationService test case checks the internal functions of the service that are responsible for parsing the JSON strings returned by the API. Tests of the translation itself have been refrained from in order to avoid incurring costs on each test run.