Instructions for how to add support for a new language to Babylscript
Updated Aug 15, 2012

How to Add a New Language to Babylscript

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