![]() TEA APIs |
In this section we'll see how to realize a support for International Languages in an easy extendible way. The code exposed is taken from the Source Codes of the TETRACTYS Enhanced Apis and is extensively used by the TEA Editor.
Three are the classes:
It takes a list of LanguageSpeakers and of the languages spoken by them. When a Change Spoken Language request takes place, it delivers that Event to all its LanguageSpeakers.
This interface defines the methods that a LanguageSpeaker must implement.
A LanguageLearner is a LanguageSpeaker that can learn new languages.
The main methods of a LanguageManager are two. First of all, addLanguageSpeaker() adds LanguageSpeakers to the LanguageManager
public void addLanguageSpeaker(LanguageSpeaker ls) { languageSpeakers.addElement(ls); for(Enumeration e = ls.getSpokenLanguages(); e.hasMoreElements();) { String l = (String)e.nextElement(); if(!isSpoken(l)) { if(spokenLanguage == null) spokenLanguage = l; addSpokenLanguage(l); } } ls.changeSpokenLanguage(spokenLanguage); }
Then, with changeSpokenLanguage() the LanguageManager can notify to the LanguageSpeakers that the user wants to change the language.
public void changeSpokenLanguage(String l) { spokenLanguage = l; for(int ct = 0; ct < languageSpeakers.size(); ct++) { ((LanguageSpeaker)languageSpeakers.elementAt(ct)). changeSpokenLanguage(l); } }Every LanguageSpeaker must have a corresponding changeSpokenLanguage() that changes labels of MenuItems, texts of Labels and so on.
A more flexible International Language Support must include the option to add new languages to the default ones supported by LanguageSpeakers. This task is realized with LanguageLearners. You can declare a LanguageLearner in a class implementing LanguageSpeaker and then use the methods learnLanguage() and setStrings(). To retrieve the String corresponding to a specified key, use the getString() method.
You can find the complete source code in the TEA APIs page. Write directly to TETRACTYS Freeware for any question or suggestion.
![]() |
In the next Issue Java Tutorials will be | ![]() |
---|