How can I make external file for Language to change menu lang. ?

Hi all ..

We all see some apps. wich we can change then menu language form menu >> Tools >> options for example ..

and most of these apps. makes the lang. file external then you can edit and make your lang file ..

how can i let my app. read the Title of the menu from external language file ?

usually , the lang. file looks like :

[Menu]

File=File

Exit= Exit

...

Pleas help ..

Thanx

[480 byte] By [bodalal] at [2008-1-9]
# 1

Hi Bodalal,

Based on your post, my understanding of your questions is that you want to localize your application. We can create the resource files to achieve this. We can take the following steps.

1. Change the Form1.Localizable property to true.

2 Set the Form1.Language property to one language.

3 Set the property of some window elements.

At last your application can get the proper information from the resource files. Hope this helps.If you have any further questions, please feel free to let me know.

Thanks for your questions.

RiquelDong–MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Thamx Dong

this is was really helpfull

hawever, i saw many apps. with external Lang. file .. so can any user change this file as he like with his lang.

i want to make external lang. file Not Locolize the project ..

thanx a gain and sorry for my bad English Smile

bodalal at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
The way I would do this, is through an external XML file. XML files are easy to parse, so you can use them well.

Add this to the top of the class:

Code Snippet

Imports System.IO

Imports System.Xml



Set up an XML reading System:

Code Snippet

Public Function ReadXml (Byval Element as String, ByVal LanguageName as String) As String
Dim m_xmlr As XmlTextReader
m_xmlr = New XmlTextReader(IO.Directory.GetCurrentDirectory() & "\language.xml")
m_xmlr.WhiteSpaceHandling = WhiteSpaceHandling.NONE
m_xmlr.Read()
m_xmlr.Read()
While Not m_xmlr.EOF
m_xmlr.Read()
'if not start element exit while loop
If Not m_xmlr.IsStartElement() Then
Exit While
End If
Dim langAttribute = m_xmlr.GetAttribute("Language")
m_xmlr.Read()

If langAttribute.ToString = LanguageName Then

Dim value = m_xmlr.ReadElementString(Element)
Return value.ToString
End If

End While
m_xmlr.Close()
End Function

Now, the hard part is that the program will have to load each of the labels individually like this:

Code Snippet

Sub New()
InitializeComponent()
Label1.Text = ReadXml("MenuTitle", "Spanish")
Label2.Text = ReadXml("WelcomeMessage", "Spanish")
Button1.Text = ReadXml("OKText", "Spanish")
Button2.Text = ReadXml("CancelText", "Spanish")
ect....
End Sub


As for the XML, it would need to look like so:

Code Snippet

<?xml version="1.0" encoding="UTF-8"?>
<ProgramSample>
<name Language="French">
<MenuTitle>asdasd</MenuTitle>
<WelcomeMessage>adasd</WelcomeMessage>

<OKText>asdasd</OKText>
<CancelText>asdasd</CancelText>

</name>
<name language="Spanish">
<MenuTitle>adasd</MenuTitle>
<WelcomeMessage>adsasdasd</WelcomeMessage>

<OKText>asdasdasd</OKText>
<CancelText>adasdasd</CancelText>

</name>

</ProgramSample>


Be warned that I just wrote this code up in this post, so it is not tested AT ALL but it should work. If it doesn't, play arround with it and it should come through for you.
NabeelAllana at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

Thanx allot Mr. Nabeel .. i really learned from your code ..

thank you for your help

best wishes

bodalal at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...