forked from gpbl/isomorphic500
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocaleSwitcher.js
52 lines (42 loc) · 1.18 KB
/
LocaleSwitcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { Component, PropTypes } from "react";
import { connectToStores } from "fluxible-addons-react";
import { locales } from "../config";
import { writeCookie } from "../utils/CookieUtils";
if (process.env.BROWSER) {
require("../style/LocaleSwitcher.scss");
}
@connectToStores([], context =>
({ currentLocale: context.getStore("IntlStore").getCurrentLocale() })
)
export default class LocaleSwitcher extends Component {
static propTypes = {
currentLocale: PropTypes.string.isRequired
}
handleLocaleClick(locale, e) {
e.preventDefault();
writeCookie("hl", locale, 365);
window.location.reload();
}
renderLocaleLink(locale) {
const { currentLocale } = this.props;
let className = "LocaleSwitcher-link";
if (locale === currentLocale) {
className = `${className} ${className}--active`;
}
return (
<a key={ locale }
className={ className }
onClick={ this.handleLocaleClick.bind(this, locale) }
href={ `?hl=${locale}` }>
{ locale }
</a>
);
}
render() {
return (
<div className="LocaleSwitcher">
{ locales.map(this.renderLocaleLink, this) }
</div>
);
}
}