Last active
February 28, 2017 17:41
-
-
Save mar9000/65062bf05b1d4cddcd1c7c6d902b0ceb to your computer and use it in GitHub Desktop.
test named slot translation (aurelia-i18n #200)
This file contains 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
<template> | |
<require from="materialize/dist/css/materialize.css"></require> | |
<require from="./named-slots"></require> | |
<!-- The following require is required as a workaround for last version of materializecss. --> | |
<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> | |
<br/> | |
<h4>Named slots</h4> | |
<named-slots> | |
<div slot="slot1" t="dialogs.slot1Content"> | |
This Goes in Slot 1 | |
</div> | |
<div slot="slot2" t="dialogs.slot2Content"> | |
This Goes in Slot 2 | |
</div> | |
</named-slot> | |
</template> |
This file contains 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 { 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); | |
} | |
} |
This file contains 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
{ | |
"dialogs" : { | |
"aDefaultCheckbox": "a default checkbox uk", | |
"slot1Content": "slot1 content uk", | |
"slot2Content": "slot2 content uk" | |
} | |
} |
This file contains 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
{ | |
"dialogs" : { | |
"aDefaultCheckbox": "a default checkbox us", | |
"slot1Content": "slot1 content us", | |
"slot2Content": "slot2 content us" | |
} | |
} |
This file contains 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
<!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> |
This file contains 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 {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; | |
} | |
} |
This file contains 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
/******************************************************************************* | |
* 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()); | |
} |
This file contains 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
<template> | |
<div> | |
The first slot: | |
<div> | |
<slot name="slot1"></slot> | |
</div> | |
The second slot: | |
<div> | |
<slot name="slot2"></slot> | |
</div> | |
</div> | |
</template> |
This file contains 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
export class NamedSlots { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment