-
Notifications
You must be signed in to change notification settings - Fork 6
Translation
NiKom, like most (all?) KOM systems, have so far always been in the Swedish language. The journey to making it multi lingual has now started and the first language to translate it to will obviously be English.
The framework of using locale.library to manage different language catalogs (on a per user level) has been put in place. The code base is still full of hard coded Swedish strings that need to be looked up in the catalogs instead to make it possible to translate them.
The catalogs are found in the Catalogs folder in the repository. The file NiKom.cd is the "Catalog definition" which defines the different strings that can be translated and holds the default (English) values for them. Then there are "catalog translation" files (.ct), one for each language. The make file uses the tool CatComp (catalog compiler) to produce the actual catalog files that can be put in the LOCALE:Catalogs directory. The make file also produces a C include file that contains all the defined strings and their default values.
Code that outputs the hardcoded Swedish strings usually look something like this (in newer, or recently refactored, code):
SendString("\r\nDu är inloggad på nod %d.\r\n", nodnr);
To make this string translatable we need to first define it NiKom.cd
MSG_LOGGED_IN_ON_NODE (501//)
You are logged in on node %d.
In the bracket after the name we have defined which id number this strings should have (501). You can also define the minimum and maximum allowed length of the strings. This is currently not used in the NiKom catalog.
Now we can change to code to use this new catalog string.
#include "Languages.h"
SendStringCat("\r\n%s\r\n", CATSTR(MSG_LOGGED_IN_ON_NODE), nodnr);
SendStringCat() is a special version of the more generic SendString() method. The first argument must contains a single "%s" together with any needed line breaks and white space characters. This will first be formatted using the catalog string. The resulting string will then be formatted using the printf() style arguments coming after the catalog string. If the catalog string doesn't contain any formatting placeholders the regular SendString() can be used.
SendString("\r\n%s\r\n", CATSTR(MSG_NO_FORMATTING));
The macro CATSTR will be expanded to the following
GetCatalogStr(g_Catalog, MSG_LOGGED_IN_ON_NODE, MSG_LOGGED_IN_ON_NODE_STR)
The first argument is the global variable that holds the catalog that is used right now. The second is the id of the string (in this case 501) and the third is the English default value. This means that even if no catalog files can be found the English default is always available.
Finally we should enter the Swedish translation in NiKom_svenska.ct.
MSG_LOGGED_IN_ON_NODE
Du är inloggad på nod %d.
; You are logged in on node %d.
The last line is a comment with the original text. This is not technically necessary but probably a good idea to see what is actually translated.
A large part of the code are still of the older style when the function SendString() didn't exist. (Since I back in the days didn't realize that you could implement your own vararg function in the same style as printf()..) This legacy code usually look like this:
sprintf(outbuffer, "\r\nDu är inloggad på nod %d.\r\n", nodnr);
puttekn(outbuffer, -1);
Before translating this it should be converted into the newer style using SendString(). The function puttekn() is deprecated and should sometime in the far future be removed.
There are obviously plenty of places where the conversion is not as straightforward as this. They will need to be dealt with on an individual basis.