简体   繁体   中英

Ember.js / Ember-i18n: Is it possible to iterate over properties within a translation file from within a Handlebars template?

Let's say I have the following translation code:

languageOptions: {
  en: {
    code: "en"
    displayName: "English"
  },
  es: {
    code: "es"
    displayName: "Español"
  }
}

I want to, from within my Handlebars template, iterate over the properties within languageOptions. I'm also using the ember-i18n plugin. Is there a way to do something like what I'm attempting to do here? (The code below, unfortunately, does not work.)

{{#each-in (t 'languageOptions') as | language | }}
    {{language}}
{{/each-in}}

I think a plain {{each}} , translating the text from within the loop, should give you the result you are looking for.

{{#each languageOptions as |language|}}
    {{t language.displayName}}
{{/each}}

You can not use like this. Because t helper returns string. You need to create a helper to return a plain object from your translations files

检查此Wiki页面( https://github.com/jamesarosen/ember-i18n/wiki/Example:-Language-Chooser ),它显示了如何做之后的事情...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM