-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-intl #609
Merged
koistya
merged 5 commits into
kriasoft:feature/react-intl
from
langpavel:feature/react-intl
Apr 22, 2016
Merged
react-intl #609
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fcd98f1
Add redux and react-redux dependencies
langpavel 69fb34f
Redux + React-redux
langpavel ced8a93
Merge branch 'langpavel-redux' into feature/redux
koistya 64ab5ce
Merge branch 'master' into feature/redux
koistya 86eadfd
React Intl
langpavel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Action creators | ||
|
||
Action Creators should go there |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import fetch from '../core/fetch'; | ||
import { | ||
SET_LOCALE_START, | ||
SET_LOCALE_SUCCESS, | ||
SET_LOCALE_ERROR, | ||
} from '../constants'; | ||
|
||
export function setLocale({ locale }) { | ||
return async (dispatch) => { | ||
dispatch({ | ||
type: SET_LOCALE_START, | ||
payload: { | ||
locale, | ||
}, | ||
}); | ||
|
||
try { | ||
const resp = await fetch('/graphql', { | ||
method: 'post', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: `query{intl(locale:${JSON.stringify(locale)}){id,message}}`, | ||
}), | ||
credentials: 'include', | ||
}); | ||
if (resp.status !== 200) throw new Error(resp.statusText); | ||
const { data } = await resp.json(); | ||
const messages = data.intl.reduce((msgs, msg) => { | ||
msgs[msg.id] = msg.message; // eslint-disable-line no-param-reassign | ||
return msgs; | ||
}, {}); | ||
dispatch({ | ||
type: SET_LOCALE_SUCCESS, | ||
payload: { | ||
locale, | ||
messages, | ||
}, | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: SET_LOCALE_ERROR, | ||
payload: { | ||
locale, | ||
error, | ||
}, | ||
}); | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SET_RUNTIME_VARIABLE } from '../constants'; | ||
|
||
export function setRuntimeVariable({ name, value }) { | ||
return { | ||
type: SET_RUNTIME_VARIABLE, | ||
payload: { | ||
name, | ||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable no-shadow */ | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { setLocale } from '../../actions/intl'; | ||
|
||
function LanguageSwitcher({ currentLocale, availableLocales, setLocale }) { | ||
const isSelected = locale => locale === currentLocale; | ||
return ( | ||
<div> | ||
{availableLocales.map(locale => ( | ||
<span key={locale}> | ||
{isSelected(locale) ? ( | ||
<span>{locale}</span> | ||
) : ( | ||
<a | ||
href={`?locale=${locale}`} | ||
onClick={(e) => { | ||
setLocale({ locale }); | ||
e.preventDefault(); | ||
}} | ||
>{locale}</a> | ||
)} | ||
{' '} | ||
</span> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
LanguageSwitcher.propTypes = { | ||
currentLocale: PropTypes.string.isRequired, | ||
availableLocales: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
setLocale: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default connect(state => ({ | ||
availableLocales: state.runtime.availableLocales, | ||
currentLocale: state.intl.locale, | ||
}), { | ||
setLocale, | ||
})(LanguageSwitcher); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "LanguageSwitcher", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "./LanguageSwitcher.js" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this branch is a little behind the
master
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, my bad.. I'm fixing this now..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, I will merge the
master
into it in a moment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging master will not help..
I done some weird rebasing against redux and master branch and this is badly copied file. Grrr 🎱