[Ivan Diaz] - Add i18n functionality and styling login widget styling tweaks

This commit is contained in:
Ivan Diaz 2015-09-30 22:22:06 -03:00
parent e46dcccd0d
commit 62e146febb
11 changed files with 94 additions and 12 deletions

View File

@ -46,6 +46,7 @@
"humps": "^0.6.0", "humps": "^0.6.0",
"jest-cli": "^0.4.19", "jest-cli": "^0.4.19",
"lodash": "^3.10.0", "lodash": "^3.10.0",
"messageformat": "^0.2.2",
"morgan": "^1.6.1", "morgan": "^1.6.1",
"react": "^0.13.x", "react": "^0.13.x",
"react-document-title": "^1.0.2", "react-document-title": "^1.0.2",

View File

@ -0,0 +1,7 @@
import Reflux from 'reflux';
var CommonActions = Reflux.createActions([
'changeLanguage'
]);
export default CommonActions;

View File

@ -1,9 +1,15 @@
import React from 'react/addons'; import React from 'react/addons';
import Reflux from 'reflux';
import {ListenerMixin} from 'reflux'; import {ListenerMixin} from 'reflux';
import {RouteHandler} from 'react-router'; import {RouteHandler} from 'react-router';
import CommonActions from 'actions/common-actions';
import CommonStore from 'stores/common-store';
var App = React.createClass({ var App = React.createClass({
mixins: [Reflux.listenTo(CommonStore, 'onCommonStoreChanged')],
render() { render() {
return ( return (
<div> <div>
@ -11,6 +17,12 @@ var App = React.createClass({
query={this.props.query} /> query={this.props.query} />
</div> </div>
); );
},
onCommonStoreChanged(change) {
if (change === 'i18n') {
this.forceUpdate();
}
} }
}); });

View File

@ -21,7 +21,7 @@ var MainHomePageLoginWidget = React.createClass({
</div> </div>
<Button type="primary">LOG IN</Button> <Button type="primary">LOG IN</Button>
</Form> </Form>
<Button type="link">{'Forgot your password?'}</Button> <Button className="login-widget--forgot-password"type="link">{'Forgot your password?'}</Button>
</Widget> </Widget>
); );
}, },

View File

@ -6,6 +6,11 @@
margin: 10px 0; margin: 10px 0;
} }
&--form { &--inputs {
margin-bottom: 20px;
}
&--forgot-password {
margin-top: 20px;
} }
} }

View File

@ -1,5 +1,7 @@
import React from 'react/addons'; import React from 'react/addons';
import Button from 'core-components/button'; import Button from 'core-components/button';
import CommonActions from 'actions/common-actions';
import i18n from 'utils/i18n';
var MainLayoutHeader = React.createClass({ var MainLayoutHeader = React.createClass({
@ -7,8 +9,10 @@ var MainLayoutHeader = React.createClass({
return ( return (
<div className="main-layout-header"> <div className="main-layout-header">
<div className="main-layout-header--login-links"> <div className="main-layout-header--login-links">
<Button type="clean" route={{to:'home'}}>Log in</Button> <Button type="clean" route={{to:'home'}}>{i18n('LOG_IN')}</Button>
<Button type="clean" route={{to:'signup'}}>Sign up</Button> <Button type="clean" route={{to:'signup'}}>Sign up</Button>
<Button type="clean" onClick={function () {CommonActions.changeLanguage('es');}}>Spanish</Button>
<Button type="clean" onClick={function () {CommonActions.changeLanguage('en');}}>English</Button>
</div> </div>
</div> </div>
); );

View File

@ -4,6 +4,6 @@
.main-layout { .main-layout {
margin: 0 auto; margin: 0 auto;
background-color: $grey; background-color: $grey;
width: 1100px; max-width: 1100px;
border-radius: 4px; border-radius: 4px;
} }

15
src/data/i18n-data.js Normal file
View File

@ -0,0 +1,15 @@
import keys from 'data/i18n-keys'
var languages = [
'en',
'es'
];
var i18nData = function (key, lang) {
var langIndex = languages.indexOf(lang);
return keys[key][langIndex];
};
export default i18nData

4
src/data/i18n-keys.js Normal file
View File

@ -0,0 +1,4 @@
export default {
'SUBMIT': ['Submit', 'Enviar'],
'LOG_IN': ['Log is', 'Logearse']
};

View File

@ -0,0 +1,19 @@
import Reflux from 'reflux';
import CommonActions from 'actions/common-actions';
var CommonStore = Reflux.createStore({
init() {
this.language = 'en';
this.listenTo(CommonActions.changeLanguage, this.changeLanguage);
},
changeLanguage(lang) {
this.language = lang;
this.trigger('i18n');
}
});
export default CommonStore;

15
src/utils/i18n.js Normal file
View File

@ -0,0 +1,15 @@
import MessageFormat from 'messageformat';
import CommonStore from 'stores/common-store';
import i18nData from 'data/i18n-data';
var mf = new MessageFormat('en');
var i18n = function (key, params = null) {
var i18nKey = i18nData(key, CommonStore.language);
var message = mf.compile(i18nKey);
return message(params);
};
export default i18n;