Skip to content

Technical Specification

Benny Lin edited this page Jul 29, 2023 · 14 revisions

Input methods are defined in javascript files. An input method is a javascript object and it is passed to $.ime.register() method to register with jquery.ime

$.ime.register( hebrewStandardKeyboard );

Metadata fields

id: A mandatory unique identifier that represents the input method. Eg: "hindi-inscript"

name: A mandatory short name for the input method. Eg: Hindi Inscript

description: An optional short description about the input method. Eg: "keyboard layout as per inscript standard"

date: An optional string to represent when this input method was written. Format should be yyyy-mm-dd

author: An optional string containing the authors name. Can contain email address as well. Eg: "Santhosh Thottingal, santhosh.thottingal@gmail.com"

URL: An optional string containing URL for the original input method definition.

license: An optional string containing licence information. Eg: "CC-BY_SA" or "GPLv3"

version: An optional string containing version information

Input method definition

patterns: A regular expression table that maps the original inputs to the target language

eg:

patterns: [
		[ 'q', '/' ],
		[ 'e', 'ק' ],
		[ 'r', 'ר' ],
		[ 't', 'א' ],
		[ 'y', 'ט' ],
		[ 'u', 'ו' ],
		[ 'i', 'ן' ],
		[ 'o', 'ם' ],
		[ 'p', 'פ' ]
		...
		// These characters are mirrored in RTL languages
		[ '\\(', ')' ],
		[ '\\)', '(' ],
		[ '\\[', ']' ],
		[ '\\]', '[' ]
	]

Any valid regular expression is possible as first element of each array item. More examples

	[ '([ക-ഹ])a', '$1ാ' ]
	[ '(([ൺ-ൿം])\u200c+)?I', '$2ഐ' ]

In the above example, $1, $2 etc are according to the normal regular expression replace syntax

The second member of pattern can be a function as well. For eg:

patterns: [ [ '[a-z]', function ( $1 ) {
			return $1.toUpperCase();
		} ] ]

This rule replace all key strokes to its upper case character

contextLength: Length of the context to remember. jquery.ime can replace the text based on the previously typed characters. Eg:

[ 'ൿh', 'c', 'ച്' ]

Note that this pattern definition has 3 members, the middle one is the context. This rule is interpreted as

The current key is h, previous key is c. For the previous key press c, we have a transliteration ൿ. But if it is followed by h and ൿ is indeed from key press c, replace ൿh with ച്

To make this work, we need to remember the previous key strokes. How many of them we need to remember? contextLength should have that value.

This is optional field with default value 0.ie, we dont remember previous key strokes by default.

maxKeyLength: While trying to find possible matches, we need to know how many characters from the current typing location(cursor) should be used before giving up.

maxKeyLength defines it. Normally it is the length of largest regex sequence in the patterns.

This field is optional and default value is 1.

Registering an input method

Input methods can be registered to jquery.ime by adding entries to $.ime.inputmethods. Even though any any input method can be loaded dynamically using $.ime.register() api, in order to display available input methods and its language association, we need information about all avallable input methods in jquery.ime.inputmethods.js

Following example shows how to map a set of input methods to a language.

$.extend( $.ime.languages, {
	'bn': {
		autonym: 'বাংলা',
		inputmethods: ['bn-avro', 'bn-inscript', 'bn-nkb', 'bn-probhat']
	}
});

If user did not select any input methods for Bengali language, the first one from inputmethods array will be default input method.

The entries of inputmethods are ids for the input methods. And should be defined as keys in $.ime.sources.

$.extend( $.ime.sources, {
	'bn-avro' : {
		name: 'Avro',
		source: 'rules/bn/bn-avro.js'
	},
	'bn-inscript' : {
		name: 'Inscript',
		source: 'rules/bn/bn-inscript.js'
	},
	'bn-nkb' : {
		name: 'National Keyboard',
		source: 'rules/bn/bn-nkb.js'
	},
	'bn-probhat' : {
		name: 'Probhat',
		source: 'rules/bn/bn-probhat.js'
	}
});

The name values will appear in the input method selector menu. source is the path to the input method definition file.

If one input method depends on another keyboard, you can specify the dependency as follows

'mai-inscript': {
	name: 'InScript',
	source: 'rules/mai/mai-inscript.js',
	depends: 'hi-inscript'
},

Loading an input method dynamically

No input method is pre loaded until user select an input method. Input methods are loaded using ajax calls, once loaded the selected input method name appears at the bottom of the textarea or input box.

Binding to editable elements

JQuery plugin function $.fn.ime can be used to bind jQuery.ime to an edit area. Eg:

$( 'jquery selector' ).ime()

input method and language preferences

$.ime.preferences abstracts the preference persisting. It exposes apis to set the input method, language preferences. This preference values are used for remembering the language selection when user navigates to another text boxes from one.

The save, load apis exposed by $.ime.preferences should be overridden if we want to persist the preferences in multiple visits to the page or even remembering across pages. The object to save it cookie or localstotorage or any custom storage mechanism is $.ime.preferences.registry. It is a json object.

User Interface

Input method selection

If there is a preferred input method from previous selections, it will selected by default on focus. If not, the default input method for current language will be selected. The selected input method will be indicated by a tick mark.

The input method can be enabled and disabled using a single short cut key CONTROL+M. Alternatively, it can be disabled using the menu link to use system input method.

Language Selection

All registered languages will be shown in the selector menu, by default. But it is possible to set the languages to be shown using input method configuration.

Once a language is cliked, it will be hidden from the language list. The language will be title for the menu, available input methods for the language will be listed for user selection.

Persisting language and input method selection

When user navigates from one editable area to another, the language preference and input method choice for that language will be remembered with the help of preferences system.

Characters need to be escaped

		[ '\\$', '' ],
		[ '\\%', '' ],
		[ '\\^', '' ],
		[ '\\&', '' ],
		[ '\\*', '' ],
		[ '\\(', '' ],
		[ '\\)', '' ],
		[ '\\_', '' ],
		[ '\\+', '' ],

		[ '\\[', '' ],
		[ '\\]', '' ],
		[ '\\\\', '' ],
		[ '\\,', '' ],
		[ '\\.', '' ],
		[ '\\/', '' ],

		[ '\\{', '' ],
		[ '\\}', '' ],
		[ '\\|', '​' ],
		[ '\\:', '' ],
		[ '\\"', '' ],
		[ '\\<', '' ],
		[ '\\>', '' ],
		[ '\\?', '' ]