Skip to content

Instantly share code, notes, and snippets.

@valichek
Last active February 23, 2017 12:57
Show Gist options
  • Save valichek/df3d84d1818a19c92ea3b96ba62d45f3 to your computer and use it in GitHub Desktop.
Save valichek/df3d84d1818a19c92ea3b96ba62d45f3 to your computer and use it in GitHub Desktop.
<template>
<h1>${message}</h1>
<require from="./object-values-value-converter"></require>
<div repeat.for="value of object | objectValues">
${value}
</div>
</template>
import {I18N} from 'aurelia-i18n';
import {inject} from 'aurelia-framework';
@inject(I18N)
export class App {
message = 'Hello World';
constructor(i18n) {
this.i18n = i18n;
this.object = {
key1: 'value1',
key2: 'value2'
};
window.setTimeout(() => {
this.object.key3 = 'value3';
//this.object = Object.assign({}, this.object, {key3: "value3"});
}, 2000);
}
changeLocale(locale) {
this.i18n.setLocale(locale);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/valichek/aurelia-bundle/i18n-0.5.2v0.0.4/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/valichek/aurelia-bundle/i18n-0.5.2v0.0.4/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
import Backend from 'i18next-xhr-backend';
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-i18n', (instance) => {
// register backend plugin
instance.i18next.use(Backend);
// adapt options to your needs (see http://i18next.com/docs/options/)
return instance.setup({
backend: { // <-- configure backend settings
loadPath: 'locale-{{lng}}-{{ns}}.json' // <-- XHR settings for where to get the files from
},
lng: 'de',
attributes: ['t', 'i18n'],
fallbackLng: 'en',
debug: true,
//compatibilityJSON: 'v1',
ns: ['translation', 'custom']
});
});
aurelia.start().then(a => a.setRoot());
}
export class ObjectValuesValueConverter {
toView(obj) {
return Object.keys(obj).map(key => {
return obj[key];
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment