PDA

View Full Version : [Classe C++] LanguageManager



wraggster
May 9th, 2008, 00:57
New from Yan2Yan (http://xtreamlua.com/modules.php?name=Forums&file=viewtopic&t=3827)

Here is a class C + + to simplify the management of language files in C + +. It is already very comprehensive, and allows, among others, running a default language ...

Download:

languageManager - Sample (http://www.zshare.net/download/117336480ae9866d/)
languageManager - Class C + + (http://www.zshare.net/download/11733672a6578b5d/)

The sample is sufficient to understand the functioning of this class, but I will explain a few things ...

How do we serve?

1. It includes the header (# include "languageManager.h")
2. It creates the object (languageManager Language;)
3. It configures the load

There are several things to load: title, which is a table that depends on the number of files languages (there will be no need to recharge), extraData which is a table in 2 dimensions which depends on the number of files and languages of imposed a number (we will not need to recharge), and text, which is a table that depends on the number imposed (on the recharge whenever you change language).
Why have thought so? extraData title and are variables that will be required all the time, but text will depend on the language chargéé (to save memory)

Code:
Langue.configure ( ". / Language /", "", 100, "def", "#");
Langue.configureDataToLoad (0, 1, NEXT, 1, NEXT, MAX);


In the first line shows the directory where the files will be stored languages, the file name to be created containing the file name default language (by default this file is called "default.lang"), maximum number of lines to load (the famous number that is imposed on text and extraData), the extension of files languages (here "def") and the character through which begin comentaires.
In the second row, said:
-- A line which must begin loading the title (0 = first line, second line 1 = ...), then the number of lines to charge for title;
-- A line which must begin loading extraData (0 = first line, second line = 1 ... NEXT = line following the end of the title), then the number of lines to charge for extraData;
-- A line which must begin loading text (0 = first line, second line = 1 ... NEXT = line following the end of extraData), then the number of lines to charge for the text (MAX = charge as much lines as possible to limit the number imposed earlier).

4. It is a research file languages and are charged with title and extraData: Langue.search ();
5. We support the language default Langue.loadDefault (), this function returns 1 if successful loading and 0 in case of non-loading (ie that the missing file is not created or that the file default language does not exist).
6. If the default load has not worked, it creates a menu choice of language then we support the language (for example: Langue.load (Langue.config-1);)
7. It may also allow accents, cédilles and others (thank you dridri85 and Akabane87):

Quote:
Langue.accentueTitle ();
Langue.accentueExtraData ();
Langue.accentueText ();


8. To access the data loaded, it was as follows:

Code:
Langue.text [i]
Langue.extraData [i] [j]
Langue.title [i]


(replacing i and j by good values)

Well, I fatigue, I will stop there, to better understand, please refer to the sample.

PS: it works well