Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

在 Firefox OS 中定制键盘

This document explains how to add custom keyboard layouts containing their own languages/scripts to Firefox OS v1.2 and up.

Gaia 内置键盘 app 状态 & system 架构

Two major features have been implemented in Firefox OS, as of October 2013.

  • A build flag to turn keyboard/spellcheck dictionaries to include in the build in the default Gaia Keyboard app on and off (see bug 884752).
  • An OS-level feature that allows users to install third-party keyboard apps from the Firefox Marketplace. This will be available starting from Firefox OS v2.0. See bug 816869 and bug 964670 for details.

To come up with a new keyboard layout, you can put a layout file in Gaia, build the keyboard app using a build config, or come up with your own keyboard app and install it on the phone.

如何生成一个键盘应用 (keyboard app)

You can use Gaia's built-in keyboard app as a template, or fork it. The basic ideas are:

  • In the manifest file, declare your app as input in the role property.
  • Make sure you have the input permission specified.

After that, you can install your keyboard, and it will show up on the bottom half of the screen whenever the user is focused to an input field. The space issues that arise from this can be dealt with by:

  • Using the old, classic window.resize to update the area your app should occupy.
  • Using the new, shiny navigator.mozInputMethod API to mutate the content of the input given; see the Mozilla Wiki KeyboardIME API page for details.

TBD: provide sample code and/or a small template app

How to add a custom layout to your template in the Gaia keyboard app

  1. See the keyboard CONFIGURE details for more information. Depending on the language you might want to add a dictionary, or include an interactive IME (for Asian languages).
  2. If you add layouts for a newly supported language, you may want to add them as default layouts for that language in build/config/keyboard-layouts.json.

Spell check / word suggestion dictionary

TBD

Asian IME

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 or software keyboard, users rely on an indexing program called input method, or IME for short, to convert a series of symbols into selections of 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. Note 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 the Gaia Keyboard app to receive symbols from the layout and output the characters. The current API is documented on Github.

We invite implementations in order to further refine this API within Gaia.

Make your IM engine work with your layout

To get your IM engine working with your keyboard layout:

  1. Put a new layout in layout.js as described in the previous section.
  2. Reference the IM engine with the imEngine property. When your layout is enabled, the keyboard app will start loading the script located at keyboard/js/imes/<imEngine>/<imEngine>.js.
  3. Set up the APIs to receive and send the keys/characters when the script is loaded and init'd.
  4. Do whatever you want in response to the user input. When the user taps any keys on the keyboard, it would typically get sent to the IM engine.

Known implementations

  • JSZhuyin is the first implementation of Gaia Keyboard Asian IM engine, for Traditional Chinese incorporating Zhuyin IME.
  • JSKanji is a prototype IM engine written for Japanese.
  • JSPinyin is 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 the Gaia keyboard.
  • JSHangul is a prototype IM engine for Korean, and is currently in development.

讨论和问答

Please come to the dev-gaia mailing list or the #gaia channel on irc.mozilla.org. #mozilla-taiwan is the de-facto Chinese-language channel for this topic.

 

文档标签和贡献者

 此页面的贡献者: chrisdavidmills, ReyCG_sub
 最后编辑者: chrisdavidmills,