How to Do Google transliteration based on Class not Id
Asked Answered
R

1

9

I am doing a Tamil Language based Web Application. In My application, l used Dynamic Fields to Add User Details. So, Dynamic Fields have multiple ids how to do this or How to use Google Transliteration based on Class?

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  // Load the Google Transliteration API
  google.load("elements", "1", {
    packages: "transliteration"
  });

  function onLoad() {
    var options = {
      sourceLanguage: 'en',
      destinationLanguage: 'ta',
      shortcutKey: 'ctrl+m',
      transliterationEnabled: true
    };

    // Create an instance on TransliterationControl with the required
    var control = new google.elements.transliteration.TransliterationControl(options);

    // Enable transliteration in the textfields with the given ids.
    var ids = ['temrorary_address', 'permanant_address', 'bankbranch', 'member_name', 'father_husband', 'workingoffice_address', ];
    control.makeTransliteratable(ids);

    // Show the transliteration control which can be used to toggle between
    // English and Hindi and also choose other destination language.
    control.showControl('translControl');
  }
  google.setOnLoadCallback(onLoad);
</script>
Rotation answered 10/6, 2017 at 5:32 Comment(0)
C
5

makeTransliteratable input may be not only an array of ids but element references as well. So you can write:

// Enable transliteration in the textfields with the given Class.
var elements = document.getElementsByClassName('Type-Your-Class-Here');
control.makeTransliteratable(elements);

But if you're adding fields dynamically, it does not help. For fields added dynamically you have to call control.makeTransliteratable every time you add new field.

Ciliary answered 17/6, 2017 at 0:29 Comment(2)
how can I translate a pre filled element?Minivet
@SuryaprakashPatel, Please consider asking a separate question instead of asking in comments. So your question would reach more people to help you.Ciliary

© 2022 - 2024 — McMap. All rights reserved.