translation(n) 1.0 "flibs"

Name

translation - Provide in-source lookup tables for strings in different languages

Table Of Contents

Synopsis

Description

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:

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

ROUTINES

There are two public routines:

call set_language( lang )

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.

character(len=*), intent(in) lang

Language to be used (nothing more than a convenient string, like "EN" or "FR"). It is used as case-sensitive.

call get_text( keyword, text, found )

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.

character(len=*), intent(in) keyword

The keyword to be looked up.

character(len=*), intent(out) text

The variable to hold the text string that was to be looked up.

logical, intent(out), optional found

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.

AUXILIARY PROGRAM

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:

    mktranslation "name-of-input-file"

It writes the file translation.inc based on the information in the input file.