translation - Provide in-source lookup tables for strings in different languages
The purpose of the translation module is to embed text strings in different languages in the source code and to look them up for a particular language. The strings are characterised by a keyword. The module comes with an auxiliary program, mktranslation.f90, that converts an input file into Fortran source code to populate the arrays that hold the strings.
The input file for the auxiliary program is very simple in structure:
The hash character(\#) introduces a comment, anything after that is ignored.
A line starting with "default:" indicates the default language to use.
A line containing the word "key:" at the start is considered the start of a new keyword.
Any other line holding a colon (:) is considered the string to be used for the previous keyword and the language given by the substring before the colon.
Here is a small example:
# Note: The translations are not necessarily correct - just serve as illustrations # Note: The keywords are case-sensitive! # default: EN key: FileNotFound EN: The file was not found: NL: Het bestand is niet gevonden: DE: Die Datei ist nicht gefunden: FR: Le fichier n'etait pas trouve: key: ErrorReadingFile EN: Error while reading the file NL: Fout bij het lezen van het bestand DE: Fehler weil das Datei wurde gelesen FR: Erreur pendant que le fichier etait lu
This file is then read by the mktranslation program and the result is in the file translation.inc for inclusion in the translation module. Using the functions set_language and get_text the program can then select in which language the text strings should be displayed:
use translation call set_language( 'FR' ) ... if ( file_not_found ) then call get_text( 'FileNotFound', text, found ) write(*,*) trim(text) endif
There are two public routines:
This subroutine sets the language to be used for looking up the required translation. If such a translation is not available, the string belonging to the default language will be returned instead.
Language to be used (nothing more than a convenient string, like "EN" or "FR"). It is used as case-sensitive.
This subroutine looks up the string that belongs to the combination of keyword and language. If that combination is not found, it returns the string for the keyword and the default language. If no such string is available either, the keyword is returned and the argument found is set to false.
The keyword to be looked up.
The variable to hold the text string that was to be looked up.
If present, set to false if the keyword was not found, otherwise to true.
Note: In combination with the flexoutput module, you can use it to create format strings that are adapted to the language of choice.
The auxiliary program can be used to convert an input file using the described keywords into an include file as used by the translation module.
The use of the program is very simple:
It writes the file translation.inc based on the information in the input file.
Copyright © 2016 Arjen Markus <arjenmarkus at sourceforge dot net>