Last active
August 29, 2015 14:20
-
-
Save weeksie/e98cac8455d4888999c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
var React = require('react'), | |
I18N = require('react-intl'), | |
I18NStore = require('stores/i18n_store'), | |
_ = require('lodash'), | |
FormattedMessage = I18N.FormattedMessage; | |
export default _.assign({ | |
getDefaultProps: function() { | |
var path = this.displayName.split('.').map(_.snakeCase).join('.'); | |
return { | |
locales: I18NStore.getLocales(), | |
messages: I18NStore.getMessages(path) | |
}; | |
}, | |
i: function(path) { | |
var rest = Array.prototype.slice(arguments, 1); | |
if(!rest) { rest = { };} | |
return <FormattedMessage message={this.m(path)} {...rest} />; | |
}, | |
m: function(path) { | |
return this.getIntlMessage(_.snakeCase(path)); | |
} | |
}, I18N.IntlMixin); |
This file contains hidden or 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
'use strict'; | |
var Reflux = require('reflux'), | |
_ = require('lodash'), | |
I18nActions = require('actions/i18n_actions'), | |
En = require('locales/en'), | |
Store; | |
Store = Reflux.createStore({ | |
listenables: [ I18nActions ] | |
init: function() { | |
this.locale = En; | |
}, | |
getLocales: function() { | |
return this.locale.locales; | |
}, | |
getMessages: function(path) { | |
if(path){ | |
return _.get(this.locale, 'messages.' + path); | |
} else { | |
return this.locale; | |
} | |
}, | |
onChangeLocale: function(locale) { | |
this.locale = locale; | |
} | |
}); | |
export default Store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment