Globalization: using another than the default language

C

cyberco

Using: WM5 PPC, .NetCF 2, C#, Visual Studio 2005

OK, I figured out how to add resources.resx files for different
languages/cultures for both my Frames and my project at large. But how
can I deploy a version of my application that uses the non-default
language? My application will run on English (also the default of my
project) versions of WM5, but my application should be in the other
language I specified.
 
D

Daniel Moth

The application will run in whatever language the device is running when
your app is launched.

Trying to work against that is more trouble than what is worth and will
require explicit coding on your behalf wherever your code needs to be
locale-aware (whereas now, it just works).

Cheers
Daniel
 
C

cyberco

The application will run in whatever language the device is running when
your app is launched.

Trying to work against that is more trouble than what is worth and will
require explicit coding on your behalf wherever your code needs to be
locale-aware (whereas now, it just works).

Yes, but unfortunately the phone is English while my application should
be in Dutch and there is no way to change the language
(CurrentUiCulture?) of a Windows Mobile 5 phone, is there?
 
M

Markus.Humm

Daniel said:
The application will run in whatever language the device is running when
your app is launched.

Trying to work against that is more trouble than what is worth and will
require explicit coding on your behalf wherever your code needs to be
locale-aware (whereas now, it just works).

If you just want to be able to show around these languages and don't
care that for some asian no chars will be displayed you can do it
without casing much trouble (except the user selecting the wrong
language and not finding back to the language dialogue).

You can name the resx files as you like so you can load them manually
somehow. But don't ask me how to do it, I know it works and we have a
app. which just uses that!

Greetings

Markus
 
P

Paul G. Tobey [eMVP]

Seems like if the application is always in Dutch, you could just build it
without trying to do any internationalization and just make everything
Dutch. In other words, forget about the OS language. Your application is
in Dutch.

Paul T.
 
C

cyberco

The application will run in whatever language the device is running when
your app is launched.
Trying to work against that is more trouble than what is worth and will
require explicit coding on your behalf wherever your code needs to be
locale-aware (whereas now, it just works).


Yes, but the problem is that the phone is using English while my
application is in Dutch. Unfortunately there is no way to change the
language of a Windows Mobile 5 device, or is there?
 
J

Jeremy

if you only care about dutch then just make all the resource strings in
dutch instead of english

since resx files are loaded based on the regional settings of the
device (but I don't mean the language of the device, I mean just the
regional settings screen) you can always manually load them based on a
user defined selection like this

I created 2 resx files in my project, one called strings.resx and the
other strings.nl.resx
in the strings.resx file there is a resource titled "title" and it's
value is "default"
in the strings.nl.resx file there is a resource titled "title" and it's
value is "dutch"

I then created 4 buttons, one to load english, generic dutch, belgian
dutch and german resources

I intentionally did not create a german resource set because I wanted
to show how the lack of a DE resource file causes it to cascade down
and use just the strings.resx set. The same goes for the EN resource
set, it will cascade and use strings.resx and the lack of a nl-BE resx
file will cause the selection of nl-BE to cascade down and use the
generic NL resx

so clicking each of the buttons below lets me change which resource set
is loaded into my global static resource set variable and the result is
that english and german users would see a form title of "default" and
people selecting dutch would see "dutch" as the form title



private void buttonEnglish_Click(object sender, EventArgs e)
{
this.SetLocalizedTitle(new
System.Globalization.CultureInfo("en"));
}

private void buttonGenericDutch_Click(object sender, EventArgs
e)
{
this.SetLocalizedTitle(new
System.Globalization.CultureInfo("nl"));
}

private void buttonBelgianDutch_Click(object sender, EventArgs
e)
{
this.SetLocalizedTitle(new
System.Globalization.CultureInfo("nl-BE"));
}

private void buttonGerman_Click(object sender, EventArgs e)
{
this.SetLocalizedTitle(new
System.Globalization.CultureInfo("de"));
}

private void SetLocalizedTitle(System.Globalization.CultureInfo
culture)
{
try
{
System.Resources.ResourceManager rm = new
System.Resources.ResourceManager("LocalizationTestApp.strings",
System.Reflection.Assembly.GetExecutingAssembly());
//I save the resource set to a static global variable
so other forms and code can access it
//the last 2 "true" parameters important, they allow
the cascade effect to happen to allow nl-BE to default to generic nl
Program.ResourceSet = rm.GetResourceSet(culture, true,
true);
//get the title resource value
this.Text = Program.ResourceSet.GetString("title");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}


Now using this means you would need to place code in your application
to update all labels and other items with the new resource strings
based on whatever resource set you just loaded dynamically

I hope this makes sense

Jeremy
 
J

joker

How would you store your strings if all the text in your system is
dynamic and could change at runtime?

For example, a user may want to customize the text on a button (and
enter custom text for the button in more than 1 language). Would you
still put this text in the resource files? or replicate the resource
files in database tables somehow?

Just curious, as this is a requirement I must solve shortly.

Thanks,
 
J

Jeremy

that's a good question, that's why I have 2 versions of that code I
posted, one reads from the compiles resx files and the other loads from
xml files that are not compiled but remain as plain text

I do write programs where the end users want to customize the UI labels
and buttons or even add a new language that was not included at the
beginning so I place all my strings in a simple xml file like this

<Localizations>
<Resource Name="DailyReports" Value="Daily Reports" />
<Resource Name="Amount" Value="Amount" />
.........
</Localizations>

I name this file something like strings.xml and it serves as the base
localization

then I create, or my end users can create, a new one based on the
original for their specific language like this one for dutch

<Localizations>
<Resource Name="DailyReports" Value="Dagrapportage" />
<Resource Name="Amount" Value="Bedrag" />
.........
</Localizations>

In my class that manages the loading of these xml files I just cascade
through the possible combinations of file names until I find the right
one

assuming someone has a PDA with the locale set to Netherlands Dutch I
would look for xml files in this order
1: strings.nl-NL.xml
2: strings.nl.xml
3: strings.xml

the benefit of leaving it as xml is that new files languages can be
added to your application without having to recompile or reinstall,
just deliver the new xml file to the device, change the locale,
reinitialize or reload the xml reading manager classes and it's loaded

and the best this is that if you don't need to differentiate between
nl-NL and nl-BE users then you just need to create strings.nl.xml and
they will both share it

the only drawback of this approach is that someone can of course damage
their xml file, accidentally delete the translation file or even
maliciously delete the translation file, but that's a price my end
users and I are willing to risk if it means we can modify and deploy
new translations without recompiling or reinstalling the whole client

Jeremy
 

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