Note that there are some explanatory texts on larger screens.

plurals
  1. POServing a language file depending on language preference settings
    text
    copied!<p>In my ember application I am supporting different languages. I am doing it this way:</p> <p>This is part of the <code>index.html</code>:</p> <pre><code>&lt;script src="scripts/vendor/ember.js"&gt;&lt;/script&gt; &lt;script src="scripts/vendor/ember-i18n.js"&gt;&lt;/script&gt; ... &lt;script&gt;window.mynamespace = {};&lt;/script&gt; &lt;script src="scripts/languages/en.js"&gt;&lt;/script&gt; &lt;script src="scripts/ember_application.js"&gt;&lt;/script&gt; </code></pre> <p>In my <code>languages/es.js</code> I configure a translations object as expected by <a href="https://github.com/jamesarosen/ember-i18n#examples" rel="nofollow">ember-i18n</a>:</p> <pre><code>var lang = { key1 : 'Translation1', ... }; window.mynamespace.lang = lang; </code></pre> <p>And now in my Ember application, I can do:</p> <pre><code>Ember.I18n.translations = window.mynamespace.lang; var App = Ember.Application.createWithMixins({...}); </code></pre> <p>I have three questions:</p> <ol> <li>Is there another approach for serving multi-lingual pages? Specifically I do not like very much the use of <code>window.mynamespace</code>, but I do not know how to share those settings before creating my ember application. </li> <li>How can I serve a different language file, for example <code>scripts/languages/es.js</code>, based on the <em>language preference settings</em> in the browser (comming in the HTTP request)?</li> <li>And this one is more difficult: how could I serve a different language file, depending on a database setting (belonging to the user profile for my application)? This setting would override the *language preference settings` coming in the HTTP request.</li> </ol>
 

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