mautilus / sdk

MAUTILUS SmartTV SDK
BSD 3-Clause "New" or "Revised" License
98 stars 43 forks source link

how to translate input's placeholder with I18N? #25

Closed kingctan closed 8 years ago

kingctan commented 8 years ago

how to translate input's placeholder with I18N?

radimbuchtela commented 8 years ago

Hi, you can use this way:

// file: i18n/en.js
I18n.translations.EN = {
    "name_placeholder": "your name"
};

// file: i18n/cs.js
I18n.translations.CS = {
    "name_placeholder": "tvé jméno"
};

Please use method onLangChange(of Snippet or Scene) to set placeholder. This method is called every time, when the language of application is changed.

// file: scene/testScene.js
/**
 * @inheritdoc Scene#init
 */
init: function() {
  this.input = new Input(null, {placeHolder: __('name_placeholder')});
  this.input.create(this.$el.find(".input-cover"));
},
/**
 * @inheritdoc Scene#onLangChange
 */
onLangChange: function (firstTime, lang) {
  this.input.placeHolder = __('name_placeholder');  // set new localized placeholder
  if(this.input.getValue().length === 0) {
    this.input.setPlaceholder(true);  // redraw placeholder, if it is visible
  }
},

Regards Radim