Subversion Repositories SvarDOS

Rev

Rev 620 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 620 Rev 814
1
 
1
 
-
 
2
 
2
              SVARLANG.LIB - THE SVARDOS TRANSLATION C LIBRARY
3
              SVARLANG.LIB - THE SVARDOS TRANSLATION C LIBRARY
3
 
4
 
-
 
5
                   Copyright (C) 2021-2022 Mateusz Viste
-
 
6
 
-
 
7
 
4
 
8
 
5
SvarLANG is a library and tooling for enabling SvarDOS applications to easily
9
SvarLANG is a library and tooling for enabling SvarDOS applications to easily
6
support multiple languages.
10
support multiple languages.
7
 
11
 
8
 
12
 
9
### PREPARING TRANSLATION FILES ###
13
### PREPARING TRANSLATION FILES ###
10
 
14
 
11
The translation files must be CATS-style text files in the usual format:
15
The translation files must be CATS-style text files in the usual format:
12
 
16
 
13
1.1:Hello, World!
17
1.1:Hello, World!
14
1.2:Help screen
18
1.2:Help screen
15
2.0:Type /? for more options
19
2.0:Type /? for more options
16
 
20
 
17
The files must be named as EN.TXT, DE.TXT, FR.TXT, etc. Then, they must be
21
The files must be named as EN.TXT, DE.TXT, FR.TXT, etc. Then, they must be
18
"compiled" into SvarLANG's binary format using the TLUMACZ tool:
22
"compiled" into SvarLANG's binary format using the TLUMACZ tool:
19
 
23
 
20
tlumacz en fr pl (...)
24
tlumacz en fr pl (...)
21
 
25
 
22
The first language provided in the command line is the reference language and
26
The first language provided in the command line is the reference language and
23
is used both as the default (embedded in the application) language, as well as
27
is used both as the default (embedded in the application) language, as well as
24
to substitute messages missing in other languages.
28
to substitute messages missing in other languages.
25
 
29
 
26
TLUMACZ computes two files:
30
TLUMACZ computes two files:
27
 
31
 
28
 * OUT.LNG   - the binary file that contains all translations
32
 * OUT.LNG   - the binary file that contains all translations
29
 * DEFLANG.C - the default translations that will be embedded into the program
33
 * DEFLANG.C - the default translations that will be embedded into the program
30
 
34
 
31
Then, DEFLANG.C must be compiled and linked to your program along with
35
Then, DEFLANG.C must be compiled and linked to your program along with
32
SVARLNGx.LIB. From there, you will be able to use the following calls:
36
SVARLNGx.LIB. From there you will be able to use SvarLANG calls, typically:
33
 
37
 
34
/* loads translations for program PROGNAME, language LANG, in the path NLSPATH.
-
 
35
 * returns 0 on success. */
-
 
36
int svarlang_load(const char *progname, const char *lang, const char *nlspath);
38
  svarlang_load("myprogram", "pl", "."); /* load .\myprogram.lng */
37
 
-
 
38
/* same as svarlang_load(), but relies on getenv() to pull LANG and NLSPATH. */
39
  puts(svarlang_str(2, 0));              /* display the string with id 2.0 */
39
int svarlang_autoload(const char *progname);
-
 
40
 
-
 
41
/* Returns a pointer to the string "id". Does not require svalang_load() to be
-
 
42
 * executed, but then it will only return the reference language strings.
-
 
43
 * a string id is the concatenation of the CATS-style identifiers, for example
-
 
44
 * string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */
-
 
45
const char *svarlang_strid(unsigned short id);
-
 
46
 
-
 
47
/* a convenience definition to fetch strings by their CATS-style pairs instead
-
 
48
 * of the 16-bit id. */
-
 
49
#define svarlang_str(x, y) svarlang_strid((x << 8) | y)
-
 
50
 
40
 
-
 
41
Read svarlang.h for more information about available functions.
51
 
42
 
52
### ENVIRONMENT ###
-
 
53
 
43
 
54
All translations files should be placed in the %NLSPATH% directory and should
-
 
55
be named the same as the program's name, with the LNG extension (for example
-
 
56
"INSTALL.LNG" if the program is named "INSTALL").
44
### ENVIRONMENT ###
57
 
45
 
-
 
46
The program translation file should be named "PROGNAME.LNG", where PROGNAME
-
 
47
is the program's name. This file should be placed in a well-known location,
-
 
48
typically the program's own directory. An exception are SvarDOS "CORE" programs
-
 
49
that store their translation files in a directory pointed out by %NLSPATH%.
-
 
50
 
58
The %LANG% environment variable defines what language should be loaded.
51
The %LANG% environment variable usually defines what language should be loaded,
-
 
52
albeit the program can just as well provide its own controls for language
-
 
53
selection and pass this information to svarlang_load() accordingly.
59
 
54
 
60
 
55
 
61
### WHY IS IT BETTER THAN CATS? ###
56
### WHY IS IT BETTER THAN CATS? ###
62
 
57
 
63
The CATS library is heavier and slower, as it embeds a text-file parser.
58
The CATS library is heavier and slower, as it embeds a text-file parser.
64
Translations also take more disk space since each file is in a separate file
59
Translations also take more disk space since each file is in a separate file
65
leading to cluster waste. Finally, CATS requires default strings to be part of
60
leading to cluster waste. Finally, CATS requires default strings to be part of
66
the application's source code, while SvarLANG keeps all strings in TXT files
61
the application's source code, while SvarLANG keeps all strings in TXT files
67
and embedds the default one inside the application in an automated way at
62
and embedds the default one inside the application in an automated way at
68
compile time.
63
compile time.
69
 
64
 
70
There is also a licensing issue: CATS/Kitten libraries are published under the
65
There is also a licensing issue: CATS/Kitten libraries are published under the
71
terms of a viral license. SvarLANG, on the other hand, is published under a
66
terms of a viral license. SvarLANG, on the other hand, is published under a
72
truly free, liberal license (MIT).
67
truly free, liberal license (MIT).
73
 
68
 
74
 
69
 
75
======================================================================= EOF ===
70
======================================================================= EOF ===
76
 
71