Last active
December 17, 2016 08:39
-
-
Save ro0gr/30453afa577921515a24c41324f4dbab to your computer and use it in GitHub Desktop.
declarative translations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| const { computed } = Ember; | |
| export default Ember.Component.extend({ | |
| content: computed('translation.content', function() { | |
| if ('then' in translation) { | |
| return translation.content; | |
| } else { | |
| return translation; | |
| } | |
| }), | |
| }).reopenClass({ | |
| positionalParams: ['translation'] | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| import emulateTranslationLoad from '../utils/load-t'; | |
| const { | |
| Controller, | |
| computed, | |
| ObjectProxy, | |
| PromiseProxyMixin | |
| } = Ember; | |
| let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin); | |
| function translation(key) { | |
| return computed(function() { | |
| return ObjectPromiseProxy.create({ | |
| promise: emulateTranslationLoad(key) | |
| }); | |
| }); | |
| } | |
| export default Controller.extend({ | |
| appName: translation('appName'), | |
| brokenTranslation: translation('blabla') | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.10.6", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.9.0", | |
| "ember-data": "2.9.0", | |
| "ember-template-compiler": "2.9.0", | |
| "ember-testing": "2.9.0" | |
| }, | |
| "addons": {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| const { | |
| RSVP, | |
| run | |
| } = Ember; | |
| const Translations = { | |
| appName: 'Ember Twiddle' | |
| }; | |
| export default function emulateTranslationLoad(key) { | |
| return new RSVP.Promise((resolve, reject) => { | |
| run.later(this, () => { | |
| if (key in Translations) { | |
| resolve(Translations[key]); | |
| } else { | |
| reject() | |
| } | |
| }, 300); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment