Click here to Skip to main content
12,402,202 members (72,064 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

6K views
343 downloads
7 bookmarked
Posted

Multilanguage Switcher from File WPF

, 3 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Multi Language Switcher Dynamically written in WPF VB.NET using XMLDataProvider

Introduction

This post is about a multi language switcher dynamically written in WPF VB.NET using XMLDataProvider:

Using the Code

Private Sub limbiSwitch_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
       Dim combo_switcher As ComboBox = DirectCast(sender, ComboBox)
       Dim e1 As XmlElement = TryCast(langSwitcher.SelectedItem, XmlElement)
       If e1 IsNot Nothing Then
           Dim result1 As XmlAttribute = TryCast(e1.Attributes("file"), XmlAttribute)
           If result1 IsNot Nothing Then
               Dim lang_filename As String = result1.Value
               If lang_filename IsNot selected_language Then
                   Dim provider = DirectCast(Me.Resources("Lang"), XmlDataProvider)
                   Dim lang_url As String = AppDomain.CurrentDomain.BaseDirectory() + _
                   "languages\" + lang_filename
                   If Not System.IO.File.Exists(lang_url) Then
                       Return
                   End If
                   provider.Source = New Uri(lang_url)
                   provider.Refresh()
               End If
           End If
       End If
   End Sub

Language names and translated words are loaded dynamically from XML files.

languages.xml

 <?xml version="1.0" encoding="utf-8"?>
<languages>
<language nume="English" file="en.xml" imagine="England.png" />
<language nume="Româna" file="ro.xml" imagine="Romania.png" />
<language nume="Dutch" file="de.xml" imagine="Germany.png" />
</languages> 

en.xml

<?xml version="1.0" encoding="utf-8"?>
<language descriere="English" ietf="en-US" version="0.8.1">
  <resources>
        <resource nume="hi">Hello, this is a test message.</resource>
</resources>
</language>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

carcabot
Romania Romania
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 3 Nov 2013
Article Copyright 2013 by carcabot
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid