Entry
BBCBASIC: Windows: How to easy get internationalization in your program? [localization]
Apr 30th, 2006 12:47
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 30 April 2006 - 04:47 pm ----------------------
BBCBASIC: Windows: How to easy get internationalization in your
program? [localization]
===
Possible general programming principles:
Centralize as much as possible (write or change in one place only, and
see that change everywhere), change as little as possible (only change
once in one place), standardize as much as possible (as much as
possible one solution), make it as dynamic as possible (changes should
be easy), portabililty (use the same on as much as possible different
systems).
A special case of this principles is the separation of data from
your source code.
---
Programmers should try from the beginning to make their programs as
dynamic as possible (that is, users should not have to change your
source code in order to change the working (e.g. using another natural
language, say French or German instead of English) of your programs).
---
One example of this principle to make your program as dynamic as
possible, is that your programs should try to get a maximal separation
of constant data and the source code of your program itself.
So that anyone can change your data outside of your program (thus
without having to recompile or change your source text in your program
again).
---
Following this principle will be more work for you as a programmer, as
you e.g. could put any constant data in external files (this separates
the data from your program, as it now is stored in files, which the
user e.g. can edit manually (or more professional, you offer some
subprogram with which to browse, set, get or search and save the data
in that file)). But if you look back later, you will be more than glad
that you have done it that way.
---
If you start with this habit of separating your data from your
source text (from the beginning):
1. -It will really help you very much in:
1. -keeping your programs maintainable for yourself
(e.g. you only have to change your data in 1 place in your
external files, instead of changing the data in a lot
of places in your program and or changing in a lot of
different files, and having to recompile which is much
more work and puzzling later).
2. -making your programs maintainable by your users
(e.g. your users can change (if it is necessary and or allowed
by you) the data themselves, without having to recompile
your program (which is often not allowed or possible,
because they do not get or have the source code). Any
commercial program will benefit from this possibility).
3. -making your programs general
1. -You could use the same data file in different programs and
or different computer languages (write your data once,
use it in all programs, all computer languages and all
databases)
(e.g. 1 (part of an) initialization file which is used by
more than one different BBCBASIC program)
(e.g. 1 initialization file which is used by BBCBASIC,
Delphi, Java, JavaScript, C++, C#, PHP, Python,
Perl, ..., MySQL, Oracle, Microsoft SQL server, ...)
If you choose XML, most languages have already designed
for you, inbuilt procedures and functions to search, set
and get your data in and out of this data files.
4. -making your programs dynamic
1. -You can change your data set on the fly. E.g. by changing
a value, the French language variables are used, instead
of the English language variables.
2. -The longer you wait in using this approach, the more difficult it
will be and the more effort it will cost later. You will then end
up in having to rewrite most of your programs (or even postpone
indefinitely or skip this task completely as it is too much work
and effort to change and rebuild it).
Thus invest now some time, and regain that with a lot of added
value later, by having much more maintainable programs.
And the need of using such an approach of separating data and
your programs will almost always appear the more experience with
programming you get.
---
2. -How to separate your data and the source code of your program
1. -Keep as much outside of your source code
1. -Start your executable program with as command line
parameter the name of your initialization file
1. -E.g. general format
<your bbcwindows executable program> <your bbcbasic
source filename> <your external initialization filename>
1. -E.g.
bbcwin.exe MyBbcProgramFilename.bbc
MyInitializationFilename.txt
-- or --
bbcwin.exe MyBbcProgramFilename.bbc
MyInitializationFilename.xml
-- or --
bbcwin.exe MyBbcProgramFilename.bbc
MyInitializationDATAFilename.dat
2. -Inside your bbcbasic program you then extract the location
of your initialization filename, by reading this command
line (use the @cmd function)
3. -Where to choose the location of your initialization file?
1. -If you are only using this data file in one program
only you could choose to store it by default in the
same current directory as your program (e.g. because
you do not have to search for it on your harddisk)
2. -If you want to use your initialization file globally
by more than 1 program, you usually put it in one
central, default location
1. -In Microsoft Windows you put this initialization
file usually in the user's 'application' directory
(because then each user gets its own, independent
from other users to change, data initialization
file)
To see where this (hidden) directory is located on
your computer, for the current Windows user login.
1. -Open an MSDOS box and type the following
command:
SET APPDATA
You see then something like
C:\Documents and
Settings\Administrator\Application Data
2. -Put (global) constant variables in your initialization file
1. -Every (global) constant (string or mathematical) variable
(e.g. something between double quotes ""), (and e.g. not
declared as LOCAL) should be located in your external
initialization file
E.g.
"USA"
"c:\mydirectory1\"
"c:\mydirectory1\myfilename"
3. -Your external data files look mostly like the following
1. Initialization file
1. -Standard initialization file (usually a text file
collection of lines with on each line something in the
following general format of a variablename followed by
a separator (like '=' or ':' followed by some other
characters))
<variablename> = <variable value>
1. -E.g.
Country = USA
Language = English
Directory = c:\mydirectory1
ErrorMessage1 = this is an error 1
InputMessage1 = please enter your name
2. To search for your variables values, you open that
initalization file, search for the variable name
(e.g. 'Country =') and when found, you extract
everything after the separator (e.g. everyting after
the '=', thus when found 'Country =', you extract
'USA')
1. -Some languages have inbuilt, ready to use
procedures or functions to search in
initialization files.
Otherwise you will have to write this procedures
and functions yourself. Thus a lot of variations
in how to solve this question, and thus no
standardization (1000 different programmers will
come up with say 1000 solutions).
3. -In your BBCBASIC programs to get the values out of
the initialization file you use then e.g. something
like (you will have to write this procedures and
functions yourself)
myVariableValue1$ = FNFileGetInitialValue
( "COUNTRY" )
myVariableValue2$ = FNFileGetInitialValue
( "LANGUAGE" )
myVariableValue3$ = FNFileGetInitialValue
( "DIRECTORY" )
myVariableValue4$ = FNFileGetInitialValue
( "ERRORMESSSAGE" )
1. -You can then e.g. put your data in arrays to
handle it more uniformly
2. -XML initialization file (by design, a hierarchical tree
like structure). You can choose the <> tag names
yourself, and in between you fill in the corresponding
data. The idea is the same, that is, you store your
initial values in a file, only the presentation (that
is using (HTML like) tags <>) is different (with regard
to the standard initialization file).
1. -E.g.
<Mydata>
<Country>
Usa
</Country>
<Language>
English
</Language>
<Directory>
English
</Directory>
<Errormessage1>
this is an error 1
</Errormessage1>
<Inputmessage1>
please enter your name
</Errormessage1>
</Mydata>
2. To search for your variables values, you open that
initalization file, search for the variable name
(e.g. '<Country>) and when found, you extract
everything until the </Country>).
---
The large advantage of working with XML is that it
is standardized. Almost every commercial
organization uses nowadays XML to exchange their
data (you can see it as small databases in text
format). Thus you could e.g. use this *same*
(central) initialization file (without changing any
of the data, which keeps it easy for you) in a lot
of other computer language (e.g. Java, C++, C#,
Delphi, ..., load it in or save it from databases
(like Microsoft SQL server, Oracle, Sybase, MySql,
...). It is easy because this computer languages and
or databases come with already designed for your
procedures and function to extract or set your XML
data.
---
The alternative is that you (and each programmer in
his own way, so a lot of different varying solutions
to the same question 'how to read data', so no
standardization anymore) write your own extraction
routines in each of this systems yourself. (1000
different programmers will come up with say 1000
solutions).
Further advantages of using XML are the possibility
to inform in a standardized way about the syntax of
your data (using a DTD or XML schema file to tell
how your data syntax should look like, so possibly
spotting errors in the representation of your data)
and the possibility to output your data in another
text format (using the XSL language to tell what it
should look like (e.g. generate a HTML page from
that data). In BBCBASIC you will have to e.g. write
this yourself, as they are currently not present.
3. -In your BBCBASIC programs to get the values out of
the XML initialization file you use then e.g.
something like (you will have to write this
procedures and functions yourself)
myVariableValue1$ = FNFileGetInitialValueXml
( "COUNTRY" )
myVariableValue2$ = FNFileGetInitialValueXml
( "LANGUAGE" )
myVariableValue2$ = FNFileGetInitialValueXml
( "DIRECTORY" )
myVariableValue2$ = FNFileGetInitialValueXml
( "ERRORMESSSAGE" )
2. -DATA files
(usually a file in BBCBASIC format (thus not directly
readable), containing a collection of lines starting with
DATA and then other information separated by commas)
DATA , , , , , , ,
DATA , , , , , , ,
DATA , , , , , , ,
DATA , , , , , , ,
DATA , , , , , , ,
1. -In BBCBASIC you can keep your DATA external, and
append it to your programs.
2. To search for your variables values, you open that DATA
file, one by one you go through your DATA values, until
you have found the value or you have reached the end.
READ <variable name>
---
Conclusion:
Using XML might be the most optimal solution, as it is the standard
for data exchange.
===
Internet: see also:
---
BBCBASIC: Windows: Internationalization: Link: Overview: Can you give
an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/40804/fid/768
----------------------------------------------------------------------