Skip to content

Instantly share code, notes, and snippets.

@fabioluz
Forked from mar9000/app.html
Created May 16, 2017 15:56
Show Gist options
  • Save fabioluz/0fa215bf67a9e445458edbdbd0937339 to your computer and use it in GitHub Desktop.
Save fabioluz/0fa215bf67a9e445458edbdbd0937339 to your computer and use it in GitHub Desktop.
bad slot projection with i18n (aurelia-i18n #197)
<template>
<!-- The following require is required as a workaround for last version of materializecss. -->
<require from="materialize/dist/css/materialize.css"></require>
<div>
<p>
<md-checkbox md-checked.bind="checked">A default checkbox</md-checkbox> with value: ${checked | stringify}
</p>
<p>
<md-checkbox md-checked="false" md-disabled="true">A disabled checkbox</md-checkbox>
</p>
<p>
<md-checkbox md-checked.bind="indeterminateChecked">An indeterminate checkbox</md-checkbox> with value: ${indeterminateChecked | stringify}
</p>
</div>
<!-- i18n support. -->
<br/>
<div>
<h4>i18n support</h4>
<select md-select value.two-way="language" change.trigger="updateLanguage()">
<option value="" disabled selected t="selectLanguage">S L</option>
<option value="en_UK">English UK</option>
<option value="en_US">English US</option>
</select>
<!-- The checkbox text should be wrapped into a span element and the translation applied to this wrapper element. -->
<md-checkbox md-checked="false"><span t="dialogs.aDefaultCheckbox">adc</span></md-checkbox>
<!-- This example is not working because of the implementation of slot translation, probably an i18n bug.
See https://github.com/aurelia-ui-toolkits/aurelia-materialize-bridge/issues/305
-->
<br/><md-checkbox md-checked="false" t="dialogs.aDefaultCheckbox">adc</md-checkbox>
</div>
</template>
import { inject } from 'aurelia-framework';
import {I18N} from 'aurelia-i18n';
@inject(I18N)
export class App {
checked = true;
indeterminateChecked = null;
constructor(i18n) {
this.i18n = i18n;
}
language;
updateLanguage() {
this.setLanguage(this.language);
}
setLanguage(l) {
this.i18n.setLocale(l);
this.toast.show('Language set to ' + l, 4000);
}
}
export class StringifyValueConverter {
toView(value) {
return JSON.stringify(value);
}
}
{
"dialogs" : {
"aDefaultCheckbox": "a default checkbox uk"
}
}
{
"dialogs" : {
"aDefaultCheckbox": "a default checkbox us"
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app="main">
<h1>Loading....</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.6/system.js"></script>
<script src="https://rawgit.com/mar9000/aurelia-materialize-bundles/0.24.0-1_i18n-2/config2.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
import {inject} from 'aurelia-framework';
import {I18N} from 'aurelia-i18n';
@inject(I18N)
export class Locale {
static LANGUAGES = new Map([
['en_UK', 'English UK'],
['en_US', 'English US']
]);
static INITIAL_LANGUAGE_KEY = 'en_UK';
constructor(i18n) {
this.i18n = i18n;
}
setLanguage(l) {
this.currentLanguageKey = l;
this.currentLanguageName = Locale.LANGUAGES.get(this.currentLanguageKey);
this.i18n.setLocale(l);
}
get languages() {
return Locale.LANGUAGES;
}
}
/*******************************************************************************
* The following two lines enable async/await without using babel's
* "runtime" transformer. Uncomment the lines if you intend to use async/await.
*
* More info here: https://github.com/jdanyow/aurelia-plunker/issues/2
*/
//import regeneratorRuntime from 'babel-runtime/regenerator';
//window.regeneratorRuntime = regeneratorRuntime;
/******************************************************************************/
import 'materialize';
import {I18N} from 'aurelia-i18n';
import Backend from 'i18next-xhr-backend';
import {Locale} from 'locale';
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-materialize-bridge', bridge => bridge.useAll() )
// Add the aurelia-i18n plugin.
.plugin('aurelia-i18n', (instance) => {
instance.i18next.use(Backend);
return instance.setup({
backend: {
loadPath: './{{lng}}_{{ns}}.json'
},
lng : Locale.INITIAL_LANGUAGE_KEY,
attributes : ['t'],
fallbackLng : Locale.INITIAL_LANGUAGE_KEY,
debug : true
});
});
aurelia.start().then(a => a.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment