I want my C# (winforms) application to be multilingual. My idea is:
- I will have my translations in some text file(s), each “sentence” or phrase will have it’s unique ID (integer)
- at the start-up of the app I will iterate through all controls on all forms I have in my app (I suppose this should be done in each form’s ‘Load’ event handler) and I will test the control of it’s type
- i.e. if it is a button or menu item, I will read it’s default ‘Text’ property, locate this phrase in one text file, read it’s unique ID and through this ID will locate translated phrase in (other) text file
- then I will overwrite that ‘Text’ property of the control with translated phrase
This enables me to have separate text file with phrases for each and every language (easy to maintain individual translation in the future – only 1 txt file)
- I would like to hear from you – proffesionals if there is some better / easier / faster / more ‘pro’ way how to accomplish this.
- What format of translation text file should I use (plain text, XML, ini….) – it should be human readable. I don’t know if finding a phrase in XML would be in C# faster than going line-by-line in plain text file and searching for given phrase/string…?
- EDIT – I want users (community) to be able to translate my app for them into their native language without my interaction (it means Microsoft’s resources are out of the game)
Thank you very much in advance.
CLOSED – My solution:
Looks like I’m staying at my original concept – every phrase will be in separate line of plain text file – Unicode encoding (and ID at the beginning of the line). I was thinking about deleting ID’s too and to use only the line numbers, but it would need advanced text editor (Notepad shows no line numbers) and if somebody accidentaly hits shortcut for “Delete line” and doesn’t notice that, whole app would go crazy 🙂
//sample of my translation text file for one language
0001:Text of my first button
0002:Text of my first label
0003:MessageBox title text
...etc etc
If you want the users to edit the translations through your application while keeping things simple and quick, resource file is best. If you don’t like it, the second best option is XML file.
Still, to answer you question on how to do it best with a text file, it is pretty straight forward: You just make sure that your unique identifier (
intprobably) are in order (validate before using the file). Then to search quickly, you use the technique of the halves.You look for number X, so you go to the file’s middle line. If id > x, to go to ¼ of the file, etc.
You cut in two until you get to the right line. This is the fastest know research method.
NOTE: Beware of the things that are external to the application but need translation: External file items, information contained in a database, etc.