Simple transliteration
The following method allows you to perform simple transliteration without a UI by manipulating JavaScript.
Method | Description |
---|---|
|
This simplified method for transliteration uses the
Result objects are produced using a JSON encoding of server requests. Consequently, we have chosen not to implement formal JavaScript objects, and instead dynamically created the While there is no formal implementation of the objects, they exist, and we document them as if there was a backing JavaScript implementation. The impact of all this is minimal. All that it means is that there is no named constructor. For each result, it's as if the system called new Object() and then set formal properties on that object. These properties are below.
|
Transliteration control JavaScript reference
The following constructor and methods allow you to perform transliteration within a UI provided by the API.
Constructor - google.elements.transliteration.TransliterationControl(options)
Constructor | Description |
---|---|
|
This method creates exceptions in the following circumstances:
The following code snippet demonstrates how to create an instance of the transliteration control: function onLoad() { var options = { sourceLanguage: 'en', destinationLanguage: ['hi'], shortcutKey: 'ctrl+g', transliterationEnabled: true }; // Create an instance on TransliterationControl with the required // options. var control = new google.elements.transliteration.TransliterationControl(options); } |
Transliteration control methods
The following methods are implemented on the google.elements.transliteration.TransliterationControl
namespace.
Method | Description |
---|---|
|
|
|
|
|
|
|
|
For right-to-left writing systems like Arabic, the API automatically adjusts the direction of the input element, according to the direction of the written script and the content of the input element. You can set the direction of text in an input element using HTML and JavaScript with You can see an example of the API's support for right-to-left languages in the Arabic transliteration example.
This method creates exceptions if any of the specified
|
|
|
|
|
|
|
|
|
Static method
The following static method is implemented on the google.language
namespace.
The following static method is implemented on the google.elements.transliteration
namespace.
Static method | Description |
---|---|
|
Enums
EventType enum
The google.elements.transliteration.TransliterationControl.EventType
enumeration lists the events that are possible during transliteration. You can provide custom handlers for these events in your code.
var google.elements.transliteration.TransliterationControl.EventType = { STATE_CHANGED : 'state_changed', LANGUAGE_CHANGED : 'language_changed', SERVER_REACHABLE : 'server_reachable', SERVER_UNREACHABLE : 'server_unreachable' };
google.elements.transliteration.TransliterationControl.EventType.STATE_CHANGED
: Results when transliteration is enabled or disabled in the transliteration control via:- A shortcut key
- The
enableTransliteration
,disableTransliteration
, ortoggleTransliteration
methods - A mouse click on the transliteration control drawn by the
showControl
method.
transliterationEnabled
. This field is true if transliteration is 'on
', else it is false.google.elements.transliteration.TransliterationControl.EventType.LANGUAGE_CHANGED
: Results when the transliteration language pair is changed in the transliteration control via:- The
setLanguagePair
method - The transliteration control drawn by the
showControl
method
sourceLanguage
anddestinationLanguage
.- The
google.elements.transliteration.TransliterationControl.EventType.SERVER_REACHABLE
: Results when you successfully contact the server to transliterate text.google.elements.transliteration.TransliterationControl.EventType.SERVER_UNREACHABLE
results upon a failed attempt to contact the server to transliterate text.
LanguageCode enum
The google.elements.transliteration.LanguageCode
maps name constants to language codes that you can use to specify the source and destination languages in the transliteration methods.
var google.elements.transliteration.LanguageCode = { ENGLISH: 'en', AMHARIC: 'am', ARABIC: 'ar', BENGALI: 'bn', CHINESE: 'zh', GREEK: 'el', GUJARATI: 'gu', HINDI: 'hi', KANNADA: 'kn', MALAYALAM: 'ml', MARATHI: 'mr', NEPALI: 'ne', ORIYA: 'or', PERSIAN: 'fa', PUNJABI: 'pa', RUSSIAN: 'ru', SANSKRIT: 'sa', SINHALESE: 'si', SERBIAN: 'sr', TAMIL: 'ta', TELUGU: 'te', TIGRINYA: 'ti', URDU: 'ur' };
SupportedDestinationLanguages enum
The google.elements.transliteration.SupportedDestinationLanguages
enumeration maps name constants to arrays of language codes that you can use to specify groups of destination languages in the transliteration control.
var google.elements.transliteration.SupportedDestinationLanguages = { // ALL includes all languages supported in the Transliterate API. // As support for more languages becomes available, this enum will be // automatically updated to include the new languages transparently. ALL: [ google.elements.transliteration.LanguageCode.AMHARIC, google.elements.transliteration.LanguageCode.ARABIC, google.elements.transliteration.LanguageCode.BENGALI, google.elements.transliteration.LanguageCode.CHINESE, google.elements.transliteration.LanguageCode.GREEK, google.elements.transliteration.LanguageCode.GUJARATI, google.elements.transliteration.LanguageCode.HINDI, google.elements.transliteration.LanguageCode.KANNADA, google.elements.transliteration.LanguageCode.MALAYALAM, google.elements.transliteration.LanguageCode.MARATHI, google.elements.transliteration.LanguageCode.NEPALI, google.elements.transliteration.LanguageCode.ORIYA, google.elements.transliteration.LanguageCode.PERSIAN, google.elements.transliteration.LanguageCode.PUNJABI, google.elements.transliteration.LanguageCode.RUSSIAN, google.elements.transliteration.LanguageCode.SANSKRIT, google.elements.transliteration.LanguageCode.SERBIAN, google.elements.transliteration.LanguageCode.SINHALESE, google.elements.transliteration.LanguageCode.TAMIL, google.elements.transliteration.LanguageCode.TELUGU, google.elements.transliteration.LanguageCode.TIGRINYA, google.elements.transliteration.LanguageCode.URDU], // INDIC includes all Indic languages supported in the Transliterate API. // As support for more Indic languages becomes available, this enum will be // automatically updated to include the new languages transparently. INDIC: [ google.elements.transliteration.LanguageCode.BENGALI, google.elements.transliteration.LanguageCode.GUJARATI, google.elements.transliteration.LanguageCode.HINDI, google.elements.transliteration.LanguageCode.KANNADA, google.elements.transliteration.LanguageCode.MALAYALAM, google.elements.transliteration.LanguageCode.MARATHI, google.elements.transliteration.LanguageCode.NEPALI, google.elements.transliteration.LanguageCode.ORIYA, google.elements.transliteration.LanguageCode.PUNJABI, google.elements.transliteration.LanguageCode.SANSKRIT, google.elements.transliteration.LanguageCode.SINHALESE, google.elements.transliteration.LanguageCode.TAMIL, google.elements.transliteration.LanguageCode.TELUGU, google.elements.transliteration.LanguageCode.URDU] };
Troubleshooting
If you encounter problems:
- Look for typos. Remember that JavaScript is a case-sensitive language.
- Use a JavaScript debugger. Google Chrome has a full set of developer tools. In Firefox, you can use the JavaScript console or the Firebug. In IE, you can use the Microsoft Script Debugger.
- Search the discussion group. If you can't find a post that answers your question, post your question to the group along with a link to a web page that demonstrates the problem.