Refresh enyo-ilib texts

Hi!

I'm trying to update the texts in my app by changing the locale of enyo-ilib. The idea is to have a first page where the user can choose is language (in my case, french and english), and then for the rest of the app the texts are in english or french. I tried setLocale(), enyo.updateLocale("fr", true), but nothing seems to work. Anybody has an idea of what I could do wrong?

Thanks!

Comments

  • Hi @sicay, did you try passing in the full locale identifier i.e. enyo.updateLocale('fr-FR');
  • Hi @aarontam!

    No I didn't. My strings.json are like this

    <br />-ressources<br /> -strings.json<br /> -en<br /> -strings.json<br /> -fr<br /> -strings.json<br />

    That's why I just enter "en" or "fr" to change the locale.

    I'm new to this enyo-ilib, so maybe I didn't made the setup correctly. Correct me if I'm wrong.
  • Is there anybody that can help me on that?
  • I have been struggling with the same problem and ended up hacking ilib glue.js

    I'll try to dig into my changes
  • That would be awesome! Thanks a lot!
  • I have no idea which version I altered, my current patched ilib version is to different from the latest release to understand what has changed :neutral:

    I need to update the code at some point the coming 2 weeks I'll keep you up to date.
  • Oh! I'm in the final phase of a project, and your code would have literally save my life. But if you can't make it quicker, I understand. I'll check for an alternative solution.

    Thanks again for you help!
  • I hope this helps you out. Here are the steps I followed to get it working:

    1. Cloned bootplate (assuming you've already done this or started your own from scratch) - git clone git@github.com:enyojs/bootplate
    2. Init submodules - git submodule update --init
    3. Added the enyo-ilib - git submodule add git@github.com:enyojs/enyo-ilib lib/enyo-ilib
    4. Added resources/strings.json, resources/en/strings.json, resources/fr/strings.json. Here's the french version if you'll pardon my french (rimshot)
    {<br />	"stuff": "French Stuff"<br />}<br />
    5. Ran debug.html from the browser
    6. From the js console in chrome:
    - ran $L('stuff') -> printed 'English stuff'
    - ran enyo.updateLocale('fr')
    - ran $L('stuff') -> printed 'French Stuff'

  • I'm using $L('stuff') in the components' titles and contents. However, when the Locale is changed by enyo.updateLocale the data already loaded in the page does not refresh. Is there any event responsible for this?
  • There's an onlocalechanged event fired. Note that $L() returns a plain ole string not a bound reference to anything so those will not automatically be updated.
  • did you solved it ? if so how did you do that ?
  • Because $L doesn't provide any kind of binding, it's best to not use it within the components block. A possible solution is to create a function that is responsible for setting all of the localized text and call it when the component is rendered and whenever the locale changes.

    Here's an example of that approach. Note that it doesn't change the text because there isn't a strings.json loaded for the locale.

    https://jsfiddle.net/3u2qdw7z/
  • Doesn't this code work for restarting the app and getting the language updated ??

    <br />handleLocaleChangeEvent: function () {<br /> // Check if the locale actually changed. Save the current locale in<br /> // your create method to compare against.<br /> if (ilib.getLocale() !== this.iLibLocale) {<br /> this.saveStateIfNecessary();<br /> if (this.canReload()) {<br /> window.location && window.location.reload();<br /> }<br /> <del></del>}<br />}<br />
  • Yea, that would work as well.
  • I'm getting the error TypeError: this.saveStateIfNecessary while trying to reload the app with thad code, any idea ?
  • sorry about the previous comment, the error would be: TypeError: this.saveStateIfNecessary is not a function
  • Not sure where that code came from but I'd consider it 'pseudo-code'. Neither saveStateIfNecessary nor canReload are intrinsic methods to Enyo so I can only infer their purpose from their names. Presumably, it's saving any interim state before reloading the app. :) You'd need to implement similar logic yourself or blindly reload the page if saving isn't necessary in your case.
  • Ok got it, fortunatelly, in my case I don't have to save the currently state of the app.. I solved it just setting the string texts in the create method of every panel. Thanks!
Sign In or Register to comment.