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
[quoted text, click to view] On Jan 12, 8:14 am, "joker" <j...@wizebid.com> wrote:
> 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,
>
> Jeremy wrote:
> > 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