Labs/Ubiquity/Parser 2/Localization Tutorial: Difference between revisions
Line 26: | Line 26: | ||
function makeParser() { | function makeParser() { | ||
var en = new Parser('en'); | var en = new Parser('en'); | ||
... | ... | ||
return en; | return en; | ||
}; | }; |
Revision as of 07:29, 22 June 2009
If you are interested in command localization, please read the wiki pages on localizing commands and making commands localizable. This entry is for adding your language to Parser 2, so you can use Ubiquity with the grammar of your language.
Introduction
Ubiquity's Parser 2 was written from the ground up with one of its greatest priorities being internationalization... not just making commands localizable, but actually making it so Parser 2 can be easily taught the grammars of other languages. Key to this undertaking is an idea from the Principles and Parameters school of linguistics, that all languages' grammars are made up of the following: (from wikipedia)
- A finite set of fundamental principles that are common to all languages; e.g., that a sentence must always have a subject, even if it is not overtly pronounced.
- A finite set of parameters that determine syntactic variability amongst languages; e.g., a binary parameter that determines whether or not the subject of a sentence must be overtly pronounced.
Following this idea, we built a flexible universal parser, Parser 2, and pair it with a (often very small) set of individual language settings.
The result of this architecture is that it takes very little code to teach Parser 2 a new language. With a little bit of JavaScript and knowledge of and interest in your own language, you’ll be able to get at least rudimentary Ubiquity functionality in your language. Follow along in this step by step guide and please submit your (even incomplete) language files.
Set up your environment
If you’re new to Ubiquity core development, you’ll want to first read the Ubiquity Development Tutorial to learn how to get a live copy of the Ubiquity repository using Mercurial.
As you read along, you may find it beneficial to follow along in some of the more complete language settings files included in Parser 2: English, Japanese, Danish.
The structure of the language file
Each language in Parser 2 gets its own settings file. You'll need to look up the ISO 639-1 code for your language... Here we'll use English (code en
) as an example here and the language settings file would then be called en.js
and go in the /ubiquity/modules/parser/new/
directory of the repository.
Here is the basic template for a Ubiquity Parser 2 language file:
function makeParser() { var en = new Parser('en'); ... return en; };
Everything here is wrapped in a factory function called makeParser
. This function initializes the new Parser
object with the appropriate language code, sets a bunch of parameters (elided above) and returns it. That's it!
Now let's walk through some of the parameters you must set to get your language working. For reference, the properties the language parser object is required to have are: branching
, anaphora
, and roles
.