Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to start an internationalized WPF-Project in SharpDevelop 4.2?
    primarykey
    data
    text
    <p>I want to create a Software, where the User can choose between several Languages. </p> <p>As a start i want to learn how to handle Internationalization, since i have never done that before.</p> <p>As IDE i use SharpDevelop or #develop, however you would spell it. I want to use C# and WPF, since i'm also learning XAML/WPF at the moment.</p> <p>So i create a new WPF-Project in ShardDevelop. On the Main Window i create a ComboBox and a TextBlock.</p> <p>The ComboBox get's two Entries: "German" and "English". The textBlock should show "Hallo Welt!" or "Hello World!", depending on the Language which is selected.</p> <p>Now comes the part where i get stuck. I guess each language get's a separate file in XML/XAML-Style (Makes sense). Where are these files and how are they and their Content loaded so that the Text of the selected Language is loaded?</p> <p>I found several examples but all are something about creating Resource-DLL and using some weird program to decompile them back into a csv-file... i don't get it, isn't there an easier way? </p> <hr> <p>I took the next Step. The Text of the TextBlock is now loaded via "{StaticResource Strings.MainForm.hwText}". It looks like this now:</p> <pre><code>&lt;TextBlock Text="{StaticResource Strings.MainForm.hwText}" /&gt; </code></pre> <p>Also I created one ResourceDictionary for German and one for English which both define the key i used in the TextBlock.</p> <p>In the Application.Resources Part i load one of the ResourceDictionary's per default.</p> <p>The Problem now is: How can i "unload" this Dictionary during Runtime and Replace it with the other?</p> <p>Of course i use the SelectionChange-Event of the ComboBox, but what do i do there?</p> <hr> <p>Problem solved!! Thanks to kmatyaszek</p> <p>Although i changed the Code of the Event-Handler a bit to my needs:</p> <pre><code>Uri baseUri = new Uri(AppDomain.CurrentDomain.BaseDirectory); Uri uri = new Uri(baseUri,"Languages\\lang."+((sender as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString()+".xaml"); if(File.Exists(uri.LocalPath) || File.Exists((uri = new Uri(baseUri,"Languages\\lang.de-DE.xaml")).LocalPath)){ ResourceDictionary dict = new ResourceDictionary(); dict.Source = uri; this.Resources.MergedDictionaries.Add(dict); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload