Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, make sure your <code>zh-CN.yml</code> is encoded in <strong>UTF-8</strong>, it looks like it's encoded in <strong>US-ASCII</strong>.</p> <h1>I18n.js</h1> <p>You can use the <code>i18n-js</code> gem to add Javascript internationalization to the Rails asset pipeline (see <a href="https://github.com/fnando/i18n-js" rel="nofollow noreferrer">https://github.com/fnando/i18n-js</a>).</p> <p>The <code>i18n-js</code> gem automatically converts the translations in the <code>config/locales/</code> directory to javascript. After you add this gem, call <code>I18n.t</code> directly in your javascript (without the <code>&lt;%=</code> and <code>%&gt;</code>). Translations are stored in javascript and can be viewed at <code>http://localhost:3000/assets/i18n/translations.js</code>.</p> <p>Note that the i18n-js may not completely load between requests, so you may still get <code>TranslationMissing</code> errors from time to time, but these should go away when you compile your assets. If this happens during development, try reloading the page.</p> <h2>Use</h2> <ol> <li>Add <code>gem 'i18n-js'</code> to your <code>Gemfile</code>.</li> <li>Run <code>bundle install</code>.</li> <li><p>Add a <code>zh-CN.yml</code> file to <code>config/locals/</code> with:</p> <pre><code>zh-CN: hello: 你好 </code></pre></li> <li><p>In <code>application.js</code>, add the i18n libraries before <code>//= require_tree .</code> and set your default locale (make sure you keep the blank line):</p> <pre><code>//= require i18n //= require i18n/translations //= require_tree . I18n.defaultLocale = "zh-CN"; </code></pre></li> <li><p>Once that's done, your <code>hello.js.coffee.erb</code> file should look like this:</p> <pre><code>$ -&gt; alert I18n.t('hello') </code></pre></li> </ol> <p>You should then get the proper internationalized alert when you visit the page.</p> <p><img src="https://i.stack.imgur.com/B4OcF.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload