Skip to content

Instantly share code, notes, and snippets.

@luxzeitlos
Last active March 24, 2017 14:50
Show Gist options
  • Save luxzeitlos/4f08a633849ad7567fadd340e5e27254 to your computer and use it in GitHub Desktop.
Save luxzeitlos/4f08a633849ad7567fadd340e5e27254 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
i18n: Ember.inject.service(),
columnsToEdit: Ember.computed('i18n.locale', function() {
let i18n = this.get('i18n');
return Ember.A([
{
"propertyName": "name",
"title": i18n.t('Name')
},
{
"propertyName": "phone",
"title": i18n.t('Name'),
},
]);
}),
columns: Ember.computed.map('columnsToEdit.[]', function(column){
return column;
}),
});
import Ember from 'ember';
const translations = {
en: {
Name: 'the name'
},
de: {
Name: 'der Name'
}
}
export default Ember.Service.extend({
init() {
this.set('locale', 'en');
},
t(key) {
return translations[this.get('locale')][key];
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<button onclick={{action (mut i18n.locale) "en"}}>en</button>
<button onclick={{action (mut i18n.locale) "de"}}>de</button>
<h2>Columns:</h2>
<ul>
{{#each columns as |c|}}
<li>
<strong>{{c.propertyName}}</strong>:
{{c.title}}
</li>
{{/each}}
</ul>
<h2>columnsToEdit</h2>
<ul>
{{#each columnsToEdit as |c|}}
<li>
<strong>{{c.propertyName}}</strong>:
{{c.title}}
</li>
{{/each}}
</ul>
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment