04-26-2013, 09:12 AM
Yes, we are in the information era, Internet was a dream in the 80s, but a reality nowadays 8)
And we are in sort of Babel tower here. This tutorial proposes a simple but effective way to make your program multilingual.
Needless to say 48Kb (actually less than 40Kb) are too little room to store all localized program texts simultaneously. My proposal is simply a structure to make our programs easily translatable to other languages. Here we go:
ZXBASIC allows commandline defines now (1.2.3-s1022), so it's possible to do something like this:
FILE: LOCALIZE.BAS
This file will include the desired language
The above file will include the desired language definition file.
FILE: ENGLISH.BAS
This defines strings in English, using #define directive
FILE: SPANISH.BAS
This defines strings in Spanish, using #define directive
FILE: hello.bas
A demo example, which will be localized.
Now, to generate for English, compile as:
To generate the same program translated into Spanish, do:
NOTICE:
We all are different native-language speakers here, so if we open-source or .bas listings, some of us would be willing to translate into our mother tongue.
What do you think of this proposal?
And we are in sort of Babel tower here. This tutorial proposes a simple but effective way to make your program multilingual.
Needless to say 48Kb (actually less than 40Kb) are too little room to store all localized program texts simultaneously. My proposal is simply a structure to make our programs easily translatable to other languages. Here we go:
ZXBASIC allows commandline defines now (1.2.3-s1022), so it's possible to do something like this:
FILE: LOCALIZE.BAS
This file will include the desired language
Code:
#ifndef LANG
' if no LANG defined, fallback to English as default
#define LANG en
#endif
' Now include the desired file
#if LANG==en
#include <english.bas>
#endif
#if LANG==es
#include <spanish.bas>
#endif
#if LANG==ru
#include <russian.bas>
#endif
FILE: ENGLISH.BAS
This defines strings in English, using #define directive
Code:
' Just HELLO WORLD
#define HELLO_WORLD "HELLO WORLD"
This defines strings in Spanish, using #define directive
Code:
' Just HELLO WORLD
#define HELLO_WORLD "HOLA MUNDO"
A demo example, which will be localized.
Code:
#include <localize.bas>
10 REM This is the MAIN code
20 PRINT HELLO_WORLD
Code:
zxb -TaB -o hello_en.tzx -D LANG=en hello.bas
Code:
zxb -TaB -o hello_es.tzx -D LANG=es hello.bas
- Use -o parameter to specify a different output file for each language
(by default ZX Basic uses just the .bas name, but will replace .bas extension with .tzx or .tap accordingly)
- Use -D <macro> = <value> to define macro values from the command line.
We all are different native-language speakers here, so if we open-source or .bas listings, some of us would be willing to translate into our mother tongue.
What do you think of this proposal?