How to Add a New Language to Babylscript
- Translate the list of keywords and objects
- Create message files for your language in the package org.mozilla.javascript.babylscript.resources
- In the babyltools directory, edit the class com.babylscript.gen.PropertiesToArrayGenerator
- in the main() function, add your language to the list of languages
- run ant babylgen to generate Java files from your message files
- Edit the class org.mozilla.javascript.TokenStream
- In that class, there is an enum called LanguageMode; add your language to the enum
- odify the methods languageModeToString(), setLanguage(), and stringToLanguageMode() to add references to your language
- Modify the clas org.mozilla.javascript.babylscript.TranslatedNameBindings
- There should be some static {} code that loads translation information from the classes generated in step 3 into the maps langResourceMap and keywordResourceMap
- dd your language there
- In the org.mozilla.javascript.babylscript package, you should create a tokenizer for your language
- These tokenizers all inherit from org.mozilla.javascript.babylscript.BabylGenericTokenizer
- Just copy the code from a tokenizer for a language similar to the one you're adding
- (Note: the DecimalNumberReader class lets you add support for multiple number formats with different decimal marks or numerals)
- Modify the class org.mozilla.javascript.BabylTokenizer
- In that class, a map called languageModeCodes is created that holds the different language codes that can be used to switch into a certain language mode
- add your language there
- Some languages have more than one language mode (for example, Russian has one language code using the Latin alphabet and another language code using the Cyrillic alphabet)
- If that is the case, you also have to modify the class org.mozilla.javascript.babylscript.TranslatedNameBindings
- Add the alternate language codes to the map EquivalentLanguageNames
- Make sure that you list your language codes in the same order each time
- When Babylscript is used as a scripting engine for Java, there is also limited runtime support for displaying and parsing international number formats
- To add support for this, you have to modify org.mozilla.javscript.ScriptRuntime
- You have to modify unlocalizeNumberString() to convert numbers to US format
-
localizeNumberString() converts US-format strings to localized strings, but it automatically uses Java locale information and does not need to be modified
- If you want to have error messages for your language, you have to add them to the package org.mozilla.javascript.resources
|