Cropster / ember-l10n

A GNU gettext based localization workflow for Ember
MIT License
15 stars 7 forks source link

tVar usage? #70

Closed ctjhoa closed 4 years ago

ctjhoa commented 4 years ago

Hi,

Can you explain a little more how tVar works? I understand that tVar is to ignore an entry in the parsing/extracting phase however you still want a translation for that entry at some point. So how do you provide a translation for tVar if it's not with the extract command?

mydea commented 4 years ago

The idea with tVar (or {{t-var}}) is that it can be for things that are dynamic. You will need to make sure yourself that it is picked up somewhere else. For example, this could work:

export default class DynamicValuesService extends Service {
  @service l10n;

  constructor() {
    super(...arguments);

    let { l10n } = this;
    this.values = [
      l10n.t('Old'),
      l10n.t('New')
    ];
  }
}
{{! template, where @status might be "Old" or "New" }}
Status: {{t-var @status}}

In most cases, it will probably be better to avoid this if possible, and use manual mapping instead, e.g.:

export default class MyComponent extends Component {
  @service l10n;

  constructor() {
    super(...arguments);

    let { l10n } = this;
    this.statusMap = [
      'Old': l10n.t('Old'),
      'New': l10n.t('New')
    ];
  }
}
Status: {{get this.statusMap @status}}