How to translate a Disko application

Preface

In most cases a Disko application deals with information that is presented to the user. The user may want to have them presented in his or her national language. To fulfill this demand disko applications can be translated even if they were not intentionally designed to be translated.

For this purpose, we have decided to use translation files, to translate any texts automatically, which are handled by the gui component.

Configuration

The concerning diskorc file (disko git version only) needs to contain following information:

<mmsrc version="1.5.0">
	...
	<language>
		<parameter name="sourcelang"      value="msgid"        />
		<parameter name="defaultdestlang" value="en"           />
		<parameter name="addtranslations" value="true"         />
		<parameter name="languagefiledir" value="./share/lang" />
	</language>
</mmsrc>

The parameter sourcelang defines the language that is been used within the application. That means the texts within the dialog files and/or the database. This is done by using the usual two letter codes (en for english, de for german, etc). In this example the sourcelang is set to msgid which means the source is no language just a placeholder. This should be your idea of using texts within your application from the very beginning. Image what problems it will cause, if you are going to correct any spell mistakes whitin your application.

The parameter defaultdestlang defines the target language that should be displayed when the application starts. The language could be changed at runtime as well. That is shown later on.

The parameter languagefiledir defines the central location of the translation files. At the program start the plugin home directories are searched for translation files as well, so that any 3rd party plugins, that provide translations, can easily be deployed as usual.

The parameter addtranslations triggers the automatic adding of text for which no translation exist in the translation files. This can be used to "generate" new skeleton files for a new language. Just create a fresh translation.en and watch it being filled automatically when choosing english for target language.

Translation files

They are named translation.<xx> wheras xx stands for the target language code. A typical translation.en where the source language are ids looks as follows:

MSG_WELCOME===Welcome
MSG_ERROR_OCCURED===There has been an error reported!
...

It is very simple. Its the sourcetext followed by 3 equal signs to separate it from the translated text. A newline finishes a single translation.

Programming example

This is a very basic example of showing the "usage" of MMSTranslator. From the programming point of view theres not much to be done. Just the .setTargetLang() method must be called to change the language which is to be displayed.

#include <mms.h>
#include <mmscore/mmstranslator.h>

int main(int argc, char *argv[]) {
    try {
        mmsInit(MMSINIT_WINDOWS,0,NULL,"./diskorc");
        MMSTranslator trans;
	
        //create my rootwindow
        MMSWindow *window;
        window = new MMSRootWindow("default_rootwindow",
                                   "100%","100%",
                                   MMSALIGNMENT_CENTER,
                                   MMSW_NONE,NULL);
        //create a label
        MMSLabelWidget *label
        label = new MMSLabelWidget(window, 
                                   "default_label", 
                                   NULL);
        string source="WELCOMEMSG";
        label->setText(source);

        //add the label to window
        window->add(label);
        window->show();
        sleep(2);

        //reset translation to a different language.
        trans.setTargetLang(MMSLANG_DE);
    } catch (MMSError *err) {
        fprintf(stderr,"%s\n",err->getMessage().c_str());
    }

    //do nothing in particular
    while(1) sleep(1);

    return 0;
}

To compile & link the sample type make in the root directory of the sample application. The application can be downloaded from here.