Skip to content

Commit 371a6be

Browse files
lcxfs1991skipjack
authored andcommitted
feat(i18n): add multiple language selection (#1148)
1 parent 23aa1ad commit 371a6be

File tree

7 files changed

+143
-9
lines changed

7 files changed

+143
-9
lines changed

assets/language/.DS_Store

6 KB
Binary file not shown.

assets/language/chinese.png

707 Bytes
Loading

assets/language/english.png

215 Bytes
Loading
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
.dropdown {
3+
position: relative;
4+
color: #fff;
5+
cursor: pointer;
6+
7+
}
8+
9+
.dropdown-language {
10+
width: 20px;
11+
height: 20px;
12+
vertical-align: middle;
13+
}
14+
15+
.dropdown-arrow {
16+
vertical-align: middle;
17+
18+
&:before {
19+
display: inline-block;
20+
margin-left: 5px;
21+
content: "\25be";
22+
}
23+
}
24+
25+
.dropdown-list {
26+
display: none;
27+
position: absolute;
28+
width: 100%;
29+
top: 45px;
30+
left: -12px;
31+
right: 0;
32+
margin: auto;
33+
background-color: #2B3A42;
34+
z-index: 1;
35+
text-align: center;
36+
37+
ul li {
38+
list-style: none;
39+
color: #fff;
40+
41+
a:link, a:visited, a:hover {
42+
color: #fff;
43+
}
44+
45+
img {
46+
width: 20px;
47+
height: 20px;
48+
// margin: 2px 0;
49+
}
50+
}
51+
}
52+
53+
.dropdown-list-show {
54+
display: inline-block;
55+
}

components/dropdown/dropdown.jsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
3+
export default class Dropdown extends React.Component {
4+
5+
constructor(props, context) {
6+
super(props, context);
7+
this.state = {
8+
isLanguageShow: false,
9+
defaultLanguage: 'english',
10+
};
11+
}
12+
13+
render() {
14+
15+
let {
16+
section,
17+
activeMod
18+
} = this.props;
19+
20+
let activeList = (this.state.isLanguageShow) ? "dropdown-list-show" : "";
21+
22+
return (
23+
<div
24+
className={ `navigation__link ${activeMod} dropdown` }
25+
onMouseOver={() => {
26+
this.setState({
27+
isLanguageShow: true
28+
});
29+
}}
30+
onMouseLeave={() => {
31+
this.setState({
32+
isLanguageShow: false
33+
});
34+
}}
35+
>
36+
<img className="dropdown-language" src={require("../../assets/language/" + this.state.defaultLanguage + ".png")}/>
37+
<i className="dropdown-arrow"></i>
38+
<div className={`dropdown-list ${activeList}`}>
39+
<ul>
40+
{
41+
section.children.map((language) => {
42+
return (
43+
<li key={language.title}>
44+
<a href={language.url}>
45+
<img src={require("../../assets/language/" + language.title + ".png")}/>
46+
</a>
47+
</li>
48+
);
49+
})
50+
}
51+
</ul>
52+
</div>
53+
</div>
54+
);
55+
}
56+
57+
}

components/navigation/navigation.jsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import Link from '../link/link';
33
import Container from '../container/container';
44
import Logo from '../logo/logo';
5+
import Dropdown from '../dropdown/dropdown';
56

67
// TODO: Maybe by updating the routing scheme later on we can avoid hardcoding this?
78
let Sections = [
@@ -36,6 +37,13 @@ let Sections = [
3637
{
3738
title: 'Support',
3839
url: 'support'
40+
},
41+
{
42+
title: 'Language',
43+
children: [
44+
{ title: 'english', url: 'https://webpack.js.org/' },
45+
{ title: 'chinese', url: 'https://doc.webpack-china.org/' }
46+
]
3947
}
4048
];
4149

@@ -61,14 +69,27 @@ export default class Navigation extends React.Component {
6169
let active = this._isActive(section);
6270
let activeMod = active ? 'navigation__link--active' : '';
6371

64-
return (
65-
<Link
66-
key={ `navigation__link-${section.title}` }
67-
className={ `navigation__link ${activeMod}` }
68-
to={ `/${section.url}` }>
69-
{ section.title }
70-
</Link>
71-
);
72+
if (section.title === 'Language') {
73+
return (
74+
<Dropdown
75+
key={ `navigation__link-${section.title}` }
76+
section={section}
77+
activeMod={activeMod}
78+
className={ `navigation__link ${activeMod}` }
79+
>
80+
</Dropdown>
81+
);
82+
}
83+
else {
84+
return (
85+
<Link
86+
key={ `navigation__link-${section.title}` }
87+
className={ `navigation__link ${activeMod}` }
88+
to={ `/${section.url}` }>
89+
{ section.title }
90+
</Link>
91+
);
92+
}
7293
})
7394
}
7495
</nav>

components/site/site.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../navigation/search-style';
1717
import '../sidebar-mobile/sidebar-mobile-style';
1818
import '../sidebar-item/sidebar-item-style';
1919
import '../logo/logo-style';
20+
import '../dropdown/dropdown-style.scss';
2021

2122
export default props => {
2223
// Retrieve section data
@@ -29,7 +30,7 @@ export default props => {
2930
url
3031
}))
3132
}));
32-
33+
3334
// Rename the root section ("webpack" => "Other") and push it to the end
3435
let rootIndex = sections.findIndex(section => section.title === 'webpack');
3536
let rootSection = sections.splice(rootIndex, 1)[0];

0 commit comments

Comments
 (0)