zewa666 / aurelia-i18next

An Aurelia-Wrapper for the i18next library
MIT License
17 stars 15 forks source link

Initial attribute translation not working as expected #21

Closed zewa666 closed 9 years ago

zewa666 commented 9 years ago

@Aaike The initial translation does not seem to happen when using Attribute based translations. A current workaround is to manually switch the locale inside attached to force reevaluation of the translation process like so:

import {EventAggregator} from 'aurelia-event-aggregator';
import {I18N} from 'aurelia-i18next';

export class Welcome {
  static inject = [I18N,Element,EventAggregator];

  constructor(i18n,element,ea) {
    this.i18n = i18n;
    this.element = element;
  }

  attached() {
    this.i18n.setLocale("de");
  }
}
Aaike commented 9 years ago

hey that is very strange , this is the BasePage that i am using , every page extends from this one. they don't have to do anything else to make it work:

export class BasePage{

  static inject = [Element,EventAggregator,I18N];
  constructor(element,ea,i18n){
    this.element = element;
    this.ea = ea;
    this.i18n = i18n;

    this.ea.subscribe('i18n:locale:changed', payload=>{
      this.updateTranslations();
    });
  }

  attached(){
    this.updateTranslations();
  }

  updateTranslations(){
    this.i18n.updateTranslations(this.element.querySelector("router-view")||this.element);
  }

}
zewa666 commented 9 years ago

Ok we really need to find a way to make VMs more extendable as you already mentioned.