Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to "localize" (translate) your program
#1
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

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
The above file will include the desired language definition file.

FILE: ENGLISH.BAS
This defines strings in English, using #define directive
Code:
' Just HELLO WORLD
#define HELLO_WORLD "HELLO WORLD"
FILE: SPANISH.BAS
This defines strings in Spanish, using #define directive
Code:
' Just HELLO WORLD
#define HELLO_WORLD "HOLA MUNDO"
FILE: hello.bas
A demo example, which will be localized.
Code:
#include <localize.bas>

10 REM This is the MAIN code
20 PRINT HELLO_WORLD
Now, to generate for English, compile as:
Code:
zxb -TaB -o hello_en.tzx -D LANG=en hello.bas
To generate the same program translated into Spanish, do:
Code:
zxb -TaB -o hello_es.tzx -D LANG=es hello.bas
NOTICE:
  • 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?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)