//svarlang.lib/autoload.c |
---|
0,0 → 1,38 |
/* This file is part of the svarlang project and is published under the terms |
* of the MIT license. |
* |
* Copyright (C) 2021-2022 Mateusz Viste |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the "Software"), |
* to deal in the Software without restriction, including without limitation |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
* and/or sell copies of the Software, and to permit persons to whom the |
* Software is furnished to do so, subject to the following conditions: |
* |
* The above copyright notice and this permission notice shall be included in |
* all copies or substantial portions of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
* DEALINGS IN THE SOFTWARE. |
*/ |
#include <stdlib.h> |
#include "svarlang.h" |
int svarlang_autoload(const char *progname) { |
const char *s; |
char langid[3]; |
s = getenv("LANG"); |
if ((s == NULL) || (*s == 0)) return(-1); |
langid[0] = s[0]; |
langid[1] = s[1]; |
langid[2] = 0; |
return(svarlang_load(progname, langid, getenv("NLSPATH"))); |
} |
//svarlang.lib/makefile |
---|
1,10 → 1,33 |
# |
# make instructions to build tlumacz.exe with OpenWatcom |
# Copyright (C) 2021 Mateusz Viste |
# make instructions to build svarlang and tlumacz.exe with OpenWatcom |
# Copyright (C) 2021-2022 Mateusz Viste |
# |
all: tlumacz.exe |
all: svarlngs.lib svarlngc.lib svarlngm.lib svarlngl.lib tlumacz.exe |
CFLAGS=-0 -wx -we -ox |
svarlngs.lib: autoload.c svarlang.c |
wcc $(CFLAGS) -ms autoload.c |
wcc $(CFLAGS) -ms svarlang.c |
wlib svarlngs.lib +autoload.obj +svarlang.obj |
svarlngc.lib: autoload.c svarlang.c |
wcc $(CFLAGS) -mc autoload.c |
wcc $(CFLAGS) -mc svarlang.c |
wlib svarlngc.lib +autoload.obj +svarlang.obj |
svarlngm.lib: autoload.c svarlang.c |
wcc $(CFLAGS) -mm autoload.c |
wcc $(CFLAGS) -mm svarlang.c |
wlib svarlngm.lib +autoload.obj +svarlang.obj |
svarlngl.lib: autoload.c svarlang.c |
wcc $(CFLAGS) -ml autoload.c |
wcc $(CFLAGS) -ml svarlang.c |
wlib svarlngl.lib +autoload.obj +svarlang.obj |
tlumacz.exe: tlumacz.c |
wcl -0 -y -cc -wx -mc -lr -we -ox tlumacz.c |
del *.obj |
//svarlang.lib/svarlang.c |
---|
26,11 → 26,14 |
#include <stdlib.h> /* NULL */ |
#include <string.h> /* memcmp(), strcpy() */ |
#include "deflang.c" |
#include "svarlang.h" |
/* supplied through DEFLANG.C */ |
extern char svarlang_mem[]; |
extern const unsigned short svarlang_memsz; |
const char *svarlang_strid(unsigned short id) { |
const char *ptr = svarlang_mem; |
/* find the string id in langblock memory */ |
86,7 → 89,7 |
} |
/* found - but do I have enough memory space? */ |
if (buff16[1] >= sizeof(svarlang_mem)) { |
if (buff16[1] >= svarlang_memsz) { |
fclose(fd); |
return(-4); |
} |
//svarlang.lib/svarlang.h |
---|
25,10 → 25,21 |
#ifndef SVARLANG_H |
#define SVARLANG_H |
/* loads translations for program PROGNAME, language LANG, in the path NLSPATH. |
* returns 0 on success. */ |
int svarlang_load(const char *progname, const char *lang, const char *nlspath); |
/* same as svarlang_load(), but relies on getenv() to pull LANG and NLSPATH. */ |
int svarlang_autoload(const char *progname); |
/* Returns a pointer to the string "id". Does not require svalang_load() to be |
* executed, but then it will only return the reference language strings. |
* a string id is the concatenation of the CATS-style identifiers, for example |
* string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */ |
const char *svarlang_strid(unsigned short id); |
/* a convenience definition to fetch strings by their CATS-style pairs instead |
* of the 16-bit id. */ |
#define svarlang_str(x, y) svarlang_strid((x << 8) | y) |
#endif |
//svarlang.lib/svarlang.txt |
---|
1,14 → 1,71 |
tlumacz is a "compiler" that builds the SvarCOM multi-lang ressource file out |
of a collection of CATS/Kitten text files. |
usage: tlumacz en fr pl ... |
SVARLANG.LIB - THE SVARDOS TRANSLATION C LIBRARY |
tlumacz generates a SVARCOM.LNG file that contains all language ressources. |
This file must be then placed in the %NLSPATH% directory so SvarCOM can find it. |
SvarCOM's language is controlled by the LANG variable (eg. "SET LANG=PL"). |
the first language acts as a reference, its strings will be used to fill any |
missing translations in other files. |
SvarLANG is a library and tooling for enabling SvarDOS applications to easily |
support multiple languages. |
a DEFAULT.LNG file is also generated, it contains only translation strings for |
the reference language. This file is only useful for building SvarCOM. |
### PREPARING TRANSLATION FILES ### |
The translation files must be CATS-style text files in the usual format: |
1.1:Hello, World! |
1.2:Help screen |
2.0:Type /? for more options |
The files must be named as EN.TXT, DE.TXT, FR.TXT, etc. Then, they must be |
"compiled" into SvarLANG's binary format using the TLUMACZ tool: |
tlumacz en fr pl (...) |
The first language provided in the command line is the reference language and |
is used both as the default (embedded in the application) language, as well as |
to substitute messages missing in other languages. |
TLUMACZ computes two files: |
* OUT.LNG - the binary file that contains all translations |
* DEFLANG.C - the default translations that will be embedded into the program |
Then, DEFLANG.C must be compiled and linked to your program along with |
SVARLNGx.LIB. From there, you will be able to use the following calls: |
/* loads translations for program PROGNAME, language LANG, in the path NLSPATH. |
* returns 0 on success. */ |
int svarlang_load(const char *progname, const char *lang, const char *nlspath); |
/* same as svarlang_load(), but relies on getenv() to pull LANG and NLSPATH. */ |
int svarlang_autoload(const char *progname); |
/* Returns a pointer to the string "id". Does not require svalang_load() to be |
* executed, but then it will only return the reference language strings. |
* a string id is the concatenation of the CATS-style identifiers, for example |
* string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */ |
const char *svarlang_strid(unsigned short id); |
/* a convenience definition to fetch strings by their CATS-style pairs instead |
* of the 16-bit id. */ |
#define svarlang_str(x, y) svarlang_strid((x << 8) | y) |
### ENVIRONMENT ### |
All translations files should be placed in the %NLSPATH% directory and should |
be named the same as the program's name, with the LNG extension (for example |
"INSTALL.LNG" if the program is named "INSTALL"). |
The %LANG% environment variable defines what language should be loaded. |
### WHY IS IT BETTER THAN CATS? ### |
The CATS library is heavier and slower, as it embeds a text-file parser. |
Translations also take more disk space since each file is in a separate file |
leading to cluster waste. Finally, CATS requires default strings to be part of |
the application's source code, while SvarLANG keeps all strings in TXT files |
and embedds the default one inside the application in an automated way at |
compile time. |
======================================================================= EOF === |
//svarlang.lib/tlumacz.c |
---|
181,7 → 181,7 |
} |
#define MEMBLOCKSZ 65500 |
#define MEMBLOCKSZ 65000 |
int main(int argc, char **argv) { |
FILE *fd; |
255,7 → 255,8 |
break; |
} |
fprintf(fd2, "/* THIS FILE HAS BEEN AUTOGENERATE BY TLUMACZ (PART OF THE SVARLANG LIBRARY) */\r\n"); |
fprintf(fd2, "static char svarlang_mem[%u] = {\r\n", sz * 2); |
fprintf(fd2, "const unsigned short svarlang_memsz = %uu;\r\n", sz * 2); |
fprintf(fd2, "char svarlang_mem[%u] = {\r\n", sz * 2); |
for (x = 0; x < sz; x++) { |
fprintf(fd2, "%u", buff[x]); |
if (x + 1 < sz) fprintf(fd2, ","); |