[Developers] Multiple Language Class - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: [Developers] Multiple Language Class (/showthread.php?tid=62834) [Developers] Multiple Language Class by deAd on 07-08-2006 at 06:51 PM
Note: download below Also, I do realize that this is a simple class and that anybody could easily see how to use it by looking at the code, but I felt like writing this example. It's not perfect, and it doesn't cover every tiny use of the class, but it gives you the main idea. quote:Notice how there are comments in the file. These will be completely ignored by the class. The class does not ignore /*...*/ comments, only // comments.Each line that is not blank and not a comment is recognized as a string. Now, we want a Spanish translation for users, so we create Spanish.txt. Each string is lined up with the corresponding string in the other file(s). Since they are ignored, comments do NOT need to be aligned. Note: these are translated with Google. They might not be accurate. quote:Now our languages are set up. Next, we need to define the windows so they can be automatically translated. For this example, I'll only show the options window. In the Windows folder, we create another .txt file containing a list of controls. The actual window's XML shows that the window's ID is WndOptions, so we call the text file WndOptions.txt. Then, we see inside the XML that there are three controls: LblServer, LblUsername, and LblPassword. So here's how our text file is set up. quote: Now we are ready to actually start using the class. Place Languages.js with your other script files, and then you can start using the code. You will need to create a global variable for the Languages object. code:BaseLanguage - a string representing the base language. Most likely English, or whatever the author is most comfortable in. This is the language used to specify what strings you want the translation of. TranslationLanguage - another string representing the language that the class will give translations in. Path - Optional. Specifies the name of the Language Files folder, if you change it. Extension - Optional. Specifies the file extension to be looked for. For this example, I'm translating the script to Spanish, with English as the base language. It uses the default path/extension, so I use this code: code: To get a translated string, you use: code:String - the string to translate in the base language. You can also use: code: Using this method, in the OnGetScriptCommands event, you can get the translation of the tooltip specified earlier: code: To create the options window, we use the CreateWnd function. It has the same parameters as the default Plus! one: code:This will create a window and automatically translate all the controls' text listed in the file for the window. To set the translation language at any time: code:Language - String representing the name of the new language To set the base language at any time: code:Language - String representing the name of the new language To set the folder path at any time (can be used to make multiple language sets): code:Path - String representing the name of the new folder To set the file extension at any time (can also be used for multiple language sets): code:Extension - String representing the extension, without a period at the beginning. To get a list of all the loaded languages, use the following, which returns an array: code: Finally, here's the download. All I ask is that you keep the header unmodified where it is. RE: [Developers] Multiple Language Class by J-Thread on 07-08-2006 at 08:31 PM
Well done!!! RE: [Developers] Multiple Language Class by deAd on 07-09-2006 at 12:49 AM Bleh. -dt- broke the unwritten rule of not doing requests someone else said they'd do...at least until the other person has released theirs RE: [Developers] Multiple Language Class by segosa on 07-09-2006 at 05:11 AM They're both good and work in different ways. Personally I prefer simplicity, so I like yours more deAd. RE: [Developers] Multiple Language Class by deAd on 07-09-2006 at 03:22 PM Thanks. I agree with your opinion on simplicity, and so I built the class to work as easily/simply as I could. glad you like it |