Help us understand the problem. What is going on with this article?

i18next tipsその1

More than 1 year has passed since last update.

PersoniumのOSS開発で下記の問題を解決したので、みなさんに共有します。

Original記事

問題

メッセージ/ラベルを英語に翻訳してHTMLタグに書き込みましたら、言語(例:日本語)を変換したでも該当メッセージ/ラベルは英語のままです。

悪い使い方

  1. 下記のコマンドを実行する。

    $('dispMsg').html(i18next.t("msg.error.fileNotFound");
    
  2. HTMLの結果。

    <div id="dispMsg">File not found.</div>
    
  3. 日本語に変換

    i18next.changeLanguage("ja");
    $('[data-i18n]').localize(); // need jQuery-i18next
    
  4. HTMLの結果(英語のまま)

    <div id="dispMsg">File not found.</div>
    

正しい使い方

  1. 下記のコマンドを実行する。

    $('#dispMsg').attr("data-i18n", "msg.error.fileNotFound")
        .localize();
    
  2. HTMLの結果。

    <div id="dispMsg" data-i18n="msg.error.fileNotFound">File not found.</div>
    
  3. 日本語に変換

    i18next.changeLanguage("ja");
    $('[data-i18n]').localize(); // need jQuery-i18next
    
  4. HTMLの結果(日本語になった!!!)

    <div id="dispMsg" data-i18n="msg.error.fileNotFound">ファイルがないです。</div>
    
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした