forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Berkeley Martinez
authored and
Berkeley Martinez
committed
Jul 29, 2016
1 parent
ee4f1db
commit 078560c
Showing
18 changed files
with
305 additions
and
79 deletions.
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
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 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router'; | ||
import supportedLanguages from '../../utils/supported-languages'; | ||
|
||
const toLowerCase = String.prototype.toLowerCase; | ||
function addLang(url, lang) { | ||
const maybeLang = toLowerCase.call(url.split('/')[1]); | ||
if (supportedLanguages[maybeLang]) { | ||
return url; | ||
} | ||
if (supportedLanguages[lang]) { | ||
return `/${lang}${url}`; | ||
} | ||
return `/en${url}`; | ||
} | ||
|
||
const mapStateToProps = state => ({ lang: state.app.lang }); | ||
|
||
export class LangLink extends React.Component { | ||
static displayName = 'LangLink'; | ||
static propTypes = { | ||
to: PropTypes.string, | ||
lang: PropTypes.string | ||
}; | ||
|
||
render() { | ||
const { | ||
to, | ||
lang, | ||
...props | ||
} = this.props; | ||
return ( | ||
<Link | ||
to={ addLang(to, lang) } | ||
{ ...props } | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(LangLink); |
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,4 @@ | ||
export default { | ||
en: 'English', | ||
es: 'Spanish' | ||
}; |
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 |
---|---|---|
@@ -1,29 +1,43 @@ | ||
import { defaultProfileImage } from '../../common/utils/constantStrings.json'; | ||
import supportedLanguages from '../../common/utils/supported-languages'; | ||
|
||
const message = | ||
'Learn to Code and Help Nonprofits'; | ||
|
||
module.exports = function(app) { | ||
var router = app.loopback.Router(); | ||
router.get('/', addDefaultImage, index); | ||
|
||
app.use( | ||
'/:lang', | ||
(req, res, next) => { | ||
// add url language to request for all routers | ||
req._urlLang = req.params.lang; | ||
next(); | ||
}, | ||
router | ||
); | ||
app.use(router); | ||
|
||
function addDefaultImage(req, res, next) { | ||
if (!req.user || req.user.picture) { | ||
return next(); | ||
} | ||
req.user.picture = defaultProfileImage; | ||
return req.user.save(function(err) { | ||
if (err) { return next(err); } | ||
return next(); | ||
}); | ||
return req.user.update$({ picture: defaultProfileImage }) | ||
.subscribe( | ||
() => next(), | ||
next | ||
); | ||
} | ||
|
||
function index(req, res) { | ||
function index(req, res, next) { | ||
if (!supportedLanguages[req._urlLang]) { | ||
return next(); | ||
} | ||
|
||
if (req.user) { | ||
return res.redirect('/challenges/current-challenge'); | ||
} | ||
|
||
return res.render('home', { title: message }); | ||
} | ||
}; |
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
Oops, something went wrong.