Multilingual Application

L

Luc The Perverse

Hello! I am looking for a good way to make an application multilingual.
Danish/English for now (but I don't want to preclude more than two languages
eventually) Every dialog will have an option for changing language (except
simple dialog boxes)

Here is what I am envisioning - I want to make sure I am on the right track:

There is a global language object which handles giving out strings, has
functions for setting/retrieving the current language and giving an array of
all available languages (in string format).

All the strings are contained in a giant hashtable and have string
references. Strings are accessed like this (this is an example only):

STable["SUREDELETE?"]

If the current language is english this could return the string "Are you
sure that you want to delete this file?"

I'm planning to embed all the strings into the program (a giant function
which contains all the strings and populates the string table on first
use) - so they could be easily edited, and avoid having to access strings
from an outside file. This is a small application, so I am not too woried
about the size of the function.

Every form would have an "updatecomponents" function which would set the
text of all affected components to their respective language.

I still need a way to trigger this updatecomponents if the language is
changed in another window, particularly if I will be making use of modeless
dialogs keeping language a global setting. Maybe windows message? (Better
ideas?)

Does this system for handling changing languages sound good?

Oh BTW - I am using Visual Studio 2003, if that makes any difference.
 
M

Marc Gravell

I can't help thinking that you are inventing the wheel... and there is
more than just the words... display formats (such as comma/period
separators, etc) can all change. Most of this is already covered in
culture-sensitive resource files... I can't remember exactly which
features were added/changed in 2.0, but in VS2005 it is quite easy to
link captions etc directly to resource entries using Localizable and
Language.

Note that some Control's will respond unkindly to the UI locale
changing underneath them... perhaps consider setting the UI-thread's
locale at the start of the app; do they genuinely change language so
often that you can't have this take effect on the next app restart
(which you could initiate)? Hooking into some global mechanism (such
as event) seems like a good way to start a memory "leak" (quoted as
not a true leak... just that the global event will still have
visibility of all the subscribers unless they *always* remember to
unsubscribe).

Marc
 
C

Cowboy \(Gregory A. Beamer\)

It is much easier to use resouce files, which will act a lot like a state
machine (much like your hashtable). And, this is already built into .NET, so
you do not have to write the mechanism.

You have two choices in the default implementation.

1. Global resources - single file for all resources. This is great for items
taht appear on multiple pages, like button captions, etc.
2. Page resources - best for localizing a single page

If you go to MSDN, however, Michele Bustamante has written a wonderful
article on using external resource DLLs and databases for your localization
efforts.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
 
C

Cowboy \(Gregory A. Beamer\)

That looks like a nice tool. :)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
Johnny Jörgensen said:
This might be an idea for you - looks really nice and easy to use to me...

http://www.jollans.com/multilang_dotnet/multilang_for_dotnet.htm

Held og lykke,
Johnny J.




Luc The Perverse said:
Hello! I am looking for a good way to make an application multilingual.
Danish/English for now (but I don't want to preclude more than two
languages eventually) Every dialog will have an option for changing
language (except simple dialog boxes)

Here is what I am envisioning - I want to make sure I am on the right
track:

There is a global language object which handles giving out strings, has
functions for setting/retrieving the current language and giving an array
of all available languages (in string format).

All the strings are contained in a giant hashtable and have string
references. Strings are accessed like this (this is an example only):

STable["SUREDELETE?"]

If the current language is english this could return the string "Are you
sure that you want to delete this file?"

I'm planning to embed all the strings into the program (a giant function
which contains all the strings and populates the string table on first
use) - so they could be easily edited, and avoid having to access strings
from an outside file. This is a small application, so I am not too
woried about the size of the function.

Every form would have an "updatecomponents" function which would set the
text of all affected components to their respective language.

I still need a way to trigger this updatecomponents if the language is
changed in another window, particularly if I will be making use of
modeless dialogs keeping language a global setting. Maybe windows
message? (Better ideas?)

Does this system for handling changing languages sound good?

Oh BTW - I am using Visual Studio 2003, if that makes any difference.
 
L

Luc The Perverse

Marc Gravell said:
I can't help thinking that you are inventing the wheel...

That's what I wanted to hear! That means I'm doing it wrong and it will be
even less work :)
and there is more than just the words... display formats (such as
comma/period separators, etc) can all change. Most of this is already
covered in culture-sensitive resource files... I can't remember exactly
which features were added/changed in 2.0, but in VS2005 it is quite easy
to link captions etc directly to resource entries using Localizable and
Language.

Note that some Control's will respond unkindly to the UI locale changing
underneath them... perhaps consider setting the UI-thread's locale at the
start of the app; do they genuinely change language so often that you
can't have this take effect on the next app restart (which you could
initiate)? Hooking into some global mechanism (such as event) seems like a
good way to start a memory "leak" (quoted as not a true leak... just that
the global event will still have visibility of all the subscribers unless
they *always* remember to unsubscribe).

All of this might be a bigger concern if I were making a much larger
application. (Understandable - I didn't give a lot of details.)

Mostly we will be working with static label boxes . . some file stuff, but
no file names will need translation.

But I thank you for the good advice - I never would have thought of
restarting the application to change language - or even having the language
run in one language its entire execution.

The application will always have a login screen at the beginning - maybe I
could have one hard coded multilingual dialog (the login) and then it could
just be set the entire time.

If the language weren't going to change then I could just get all the text
set at dialog initialization - the only text I'd ever need to fetch would be
some messageboxes.

Suddenly things are looking up!
 
L

Luc The Perverse

Cowboy (Gregory A. Beamer) said:
It is much easier to use resouce files, which will act a lot like a state
machine (much like your hashtable). And, this is already built into .NET,
so you do not have to write the mechanism.

You have two choices in the default implementation.

1. Global resources - single file for all resources. This is great for
items taht appear on multiple pages, like button captions, etc.
2. Page resources - best for localizing a single page

If you go to MSDN, however, Michele Bustamante has written a wonderful
article on using external resource DLLs and databases for your
localization efforts.

Thank you :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top