【问题标题】:How to Do Google transliteration based on Class not Id如何根据 Class 而不是 Id 进行 Google 音译
【发布时间】:2017-11-12 04:30:10
【问题描述】:

我正在做一个基于泰米尔语的 Web 应用程序。在我的应用程序中,我使用动态字段来添加用户详细信息。那么,Dynamic Fields 有多个 ids 如何做到这一点或如何使用基于 Class 的 Google Transliteration?

<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>

【问题讨论】:

    标签: javascript google-translate google-translator-toolkit


    【解决方案1】:

    makeTransliteratable 输入可能不仅是一个 id 数组,还可能是元素引用。 所以你可以写:

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

    但如果您是动态添加字段,则无济于事。对于动态添加的字段,您必须在每次添加新字段时调用control.makeTransliteratable。

    【讨论】:

    • 如何翻译预填充的元素?
    • @SuryaprakashPatel,请考虑单独提问,而不是在 cmets 中提问。因此,您的问题会吸引更多的人来帮助您。
    • @Kosh 你救了我一整天.. !!谢谢老兄。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-28
    • 2012-08-06
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 2018-04-02
    相关资源
    最近更新 更多