Translate custom attributes with i18next (placeholder, value)

后端 未结 3 1850
傲寒
傲寒 2020-12-31 07:26

I am investigating what is possible with i18next localization library.

Right now I have the following code (full Fiddle is here):

HTML

相关标签:
3条回答
  • 2020-12-31 07:37

    Consider calling

    $('body').i18n()
    

    inside .done() function. You should tell where to look for localizer. This will work without having to call [placeholders] in the data-i18n attribute.

    0 讨论(0)
  • 2020-12-31 07:44

    For me the following worked

    <input data-i18n="[placeholder]placeTransl" value="name">
    

    So just enter the attribute's name between [] and then the translation.

    0 讨论(0)
  • 2020-12-31 07:46

    After asking i18next creator this question directly, I received the following reply: all I need is to put my custom attribute in front of the translation element. Here is an example:

    <div data-i18n="[title]titleTransl"></div>
    <input data-i18n="[placeholder]placeTransl" value="name">
    

    If multiple attributes are needed, separate them by a ;.

    I learned 2 things by this:

    • I have to read better documentation.
    • 118next's creator is really helpful (this is a thank you remark for him).
    0 讨论(0)
提交回复
热议问题