FAQ  •  Register  •  Login

How to "localize" (translate) your program

<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Apr 26, 2013 9:12 am

How to "localize" (translate) your program

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?
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Wed May 01, 2013 10:30 pm

Re: How to "localize" (translate) your program

I suppose, it is possible to define multiple macros, right?
-D LANG=de -D VERSION=hard -D RATING=adult
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed May 01, 2013 11:53 pm

Re: How to "localize" (translate) your program

LCD wrote:I suppose, it is possible to define multiple macros, right?
-D LANG=de -D VERSION=hard -D RATING=adult

Yes, or that's the idea. :P

Note this is currently *beta* in 1.3.0.
The next version will have it more tested, since macros now allows also #if directives. e.g.
  Code:
#if LANG==de && VERSION==hard || RATING=adult
PRINT "bla bla"
#else
PRINT "ble ble"
#endif

In a similar (but limited) way, as explained here: http://gcc.gnu.org/onlinedocs/cpp/If.html#If
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Thu May 02, 2013 7:44 am

Re: How to "localize" (translate) your program

boriel wrote:
LCD wrote:I suppose, it is possible to define multiple macros, right?
-D LANG=de -D VERSION=hard -D RATING=adult

Yes, or that's the idea. :P

Note this is currently *beta* in 1.3.0.
The next version will have it more tested, since macros now allows also #if directives. e.g.
  Code:
#if LANG==de && VERSION==hard || RATING=adult
PRINT "bla bla"
#else
PRINT "ble ble"
#endif

In a similar (but limited) way, as explained here: http://gcc.gnu.org/onlinedocs/cpp/If.html#If


Oh, that is great and I can imagine some uses for it, apart from Languages.
So this is C Plusplus syntax...

I think, I will try to use it without splitting into multiple sources:
  Code:
#ifndef LANG
' if no LANG defined, fallback to English as default
#define LANG en
#endif

#if LANG==en
#define HELLO_WORLD "HELLO WORLD"
#define OTHER_TEXT "OTHER TEXT"
#endif

#if LANG==de
#define HELLO_WORLD "HALLO WELT"
#define OTHER_TEXT "ANDERER TEXT"
#endif


PRINT OTHER_TEXT
PrintString(@Message1)
END
Message1:
ASM
  DEFB 16,7
  DEFM HELLO_WORLD
END ASM

------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu May 02, 2013 8:04 am

Re: How to "localize" (translate) your program

LCD wrote:Oh, that is great and I can imagine some uses for it, apart from Languages.
So this is C Plusplus syntax...

I think, I will try to use it without splitting into multiple sources:

Right!
But if you plan to give the lang source to other people to translate to their native language, I think it would be better to give them only a separated translation include file (e.g. because you don't want to give them the complete source).
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Thu May 02, 2013 11:47 am

Re: How to "localize" (translate) your program

boriel wrote:Right!
But if you plan to give the lang source to other people to translate to their native language, I think it would be better to give them only a separated translation include file (e.g. because you don't want to give them the complete source).

In this case you are absolutly right...
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

JBGV

Posts: 65

Joined: Wed Feb 16, 2011 6:12 am

Post Mon May 06, 2013 11:32 am

Re: How to "localize" (translate) your program

boriel wrote:What do you think of this proposal?


It is a very good idea !

Translation is a headache for me :oops:
<<

cheveron

User avatar

Posts: 71

Joined: Sat Dec 11, 2010 11:22 pm

Post Thu May 29, 2014 4:15 pm

Re: How to "localize" (translate) your program

Just a couple of things to throw out there. As well as language specific strings, ZXodus uses language specific compression code (digraphs) and character sets.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri May 30, 2014 9:18 am

Re: How to "localize" (translate) your program

cheveron wrote:Just a couple of things to throw out there. As well as language specific strings, ZXodus uses language specific compression code (digraphs) and character sets.

You could also use conditional #ifdef directives, for example, and use #incbin with them.

Return to How-To & Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO