Gaia/System/Keyboard/Layout
Hello! The goal of this document is to allow people to add keyboard layout of their own language/script on the v1.2 Gaia Keyboard app.
Status of the Gaia Keyboard app & system architecture
As of Oct 2013, two major features have been recently implemented in Firefox OS.
- A build flag exist to turn on/off keyboard/spellcheck dictionary to include in the build, in the default Gaia Keyboard app (see bug 884752).
- An OS-level feature that allow users to install 3rd-party keyboard apps from marketplace. See bug 816869.
To come up with a new keyboard layout, you could either put a layout file in Gaia, build the keyboard app with a build config, or come up with your own keyboard app and install it to the phone.
How-tos: make a keyboard app
You might want to use the built-in keyboard as a template, or fork it. The basic ideas are
- In the manifest, declare yourself as a keyboard in the
role
property. - Make sure you have the
keyboard
permission.
After that, after installation and activation, your keyboard will show up on the bottom half of the screen whenever the user is focused to a input field.
- Use the old, classic
window.resize
to update the area of your app should occupy. - Use the new, shiny
navigator.mozInputMethod
API to mutate the content of the input given, see API page for detail.
(some sample code and/or a small template app will help here)
How-tos: add your layout to your in the Gaia keyboard app
See apps/keyboard/CONFIGURE for detail. Depend on the language, you might want to add a dictionary, or include an interactive IME (for Asian languages).
Spell check / word suggestion dictionary
(TBA)
Asian IME
Introduction
East Asian languages (Chinese, Japanese, and Korean) use a fairly complex script that involves thousands of characters. As there is no way to put thousands of keys on a hardware keyboard nor a software keyboard, users would rely on a piece of indexing program called input method, or IME for short, to convert series of symbols into a selections of candidate characters.
How symbols should be converted and how "smart" the IME should be depends on the method chosen, implementation itself, and often NLP science, which is outside the scope of this document. One thing to note is that it is highly recommended to put the database part into IndexedDB, in order to conserve memory on a mobile device.
IM Engine interface in Gaia keyboard app
Assuming you have an IME library readily available for converting symbols into characters (IM Engine in our terminology), you would need to use the defined interface within Gaia Keyboard app, available to the library to receive symbols from the layout, and to output the characters. The current API is documented in the comment here. We invite implementations in order to further refine this API within Gaia.
Make your IM engine work with your layout
- Put a new layout in layout.js as the previous section described.
- Reference the IM engine with
imEngine
property. When your layout is enabled, the keyboard app would start loading the script located atkeyboard/js/imes/<imEngine>/<imEngine>.js
. - APIs to receive and send the keys/characters should be setup when the script is loaded and
init
'd. - When the user tap any key/symbols on the keyboard, it would get send to the IM engine. Do whatever you want in response to the user input.
Known implementations
- JSZhuyin is the first implementation of Gaia Keyboard Asian IM engine, for Zhuyin IME for Traditional Chinese. Blame the author if you think the current API sucks.
- JSKanji is a prototype IM engine written for Japanese.
- JSPinyin is a written for Simplified Chinese and works by tapping Pinyin symbols.
- As a demonstration, Chewing, an C/C++ open-source Zhuyin IME for Traditional Chinese, was cross-compiled with emscripten and linked with Gaia keyboard.
- JSHangul will be a prototype IM engine for Korean.
Discussion, Q&A, etc
Please come to dev-gaia mailing list or the #gaia
channel on irc.mozilla.org. #mozilla-taiwan
is the de-facto Chinese-language channel for this topic.