Skip to content

Commit 6805af5

Browse files
committed
feat: support multi-language configuration
1 parent 4b9d1eb commit 6805af5

File tree

4 files changed

+207
-177
lines changed

4 files changed

+207
-177
lines changed

src/DemoBlock.vue

Lines changed: 14 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -41,182 +41,9 @@
4141
</div>
4242
</template>
4343

44-
<style lang="less">
45-
.demo-block {
46-
border: solid 1px #ebebeb;
47-
border-radius: 3px;
48-
transition: 0.2s;
49-
margin-top: 15px;
50-
margin-bottom: 15px;
51-
&.hover {
52-
box-shadow: 0 0 8px 0 rgba(232, 237, 250, 0.6),
53-
0 2px 4px 0 rgba(232, 237, 250, 0.5);
54-
}
55-
code {
56-
font-family: Menlo, Monaco, Consolas, Courier, monospace;
57-
}
58-
.demo-button {
59-
float: right;
60-
}
61-
.demo-content {
62-
padding: 24px;
63-
}
64-
.meta {
65-
background-color: #282c34;
66-
border: solid 1px #ebebeb;
67-
border-radius: 3px;
68-
overflow: hidden;
69-
height: 0;
70-
transition: height 0.2s;
71-
}
72-
.description {
73-
padding: 20px;
74-
box-sizing: border-box;
75-
border: solid 1px #ebebeb;
76-
border-radius: 3px;
77-
font-size: 14px;
78-
line-height: 22px;
79-
color: #666;
80-
word-break: break-word;
81-
margin: 10px;
82-
background-color: #fafafa;
83-
}
84-
.code-content {
85-
pre[class*="language-"] {
86-
padding: 16px;
87-
margin: 8px 0;
88-
}
89-
}
90-
.demo-block-control {
91-
border-top: solid 1px #eaeefb;
92-
height: 44px;
93-
box-sizing: border-box;
94-
background-color: #fafafa;
95-
border-bottom-left-radius: 4px;
96-
border-bottom-right-radius: 4px;
97-
text-align: center;
98-
margin-top: -1px;
99-
color: #d3dce6;
100-
cursor: pointer;
101-
position: relative;
102-
103-
&.is-fixed {
104-
position: fixed;
105-
bottom: 0;
106-
width: 660px;
107-
z-index: 999;
108-
}
109-
110-
.icon {
111-
font-family: element-icons !important;
112-
font-style: normal;
113-
font-weight: 400;
114-
font-variant: normal;
115-
text-transform: none;
116-
line-height: 1;
117-
vertical-align: baseline;
118-
display: inline-block;
119-
-webkit-font-smoothing: antialiased;
120-
}
121-
122-
.caret-top {
123-
&::before {
124-
content: "";
125-
position: absolute;
126-
right: 50%;
127-
width: 0;
128-
height: 0;
129-
border-bottom: 6px solid #ccc;
130-
border-right: 6px solid transparent;
131-
border-left: 6px solid transparent;
132-
}
133-
}
134-
135-
.caret-bottom {
136-
&::before {
137-
content: "";
138-
position: absolute;
139-
right: 50%;
140-
width: 0;
141-
height: 0;
142-
border-top: 6px solid #ccc;
143-
border-right: 6px solid transparent;
144-
border-left: 6px solid transparent;
145-
}
146-
}
147-
148-
i {
149-
font-size: 16px;
150-
line-height: 44px;
151-
transition: 0.3s;
152-
&.hovering {
153-
transform: translateX(-40px);
154-
}
155-
}
156-
157-
> span {
158-
position: absolute;
159-
transform: translateX(-30px);
160-
font-size: 14px;
161-
line-height: 44px;
162-
transition: 0.3s;
163-
display: inline-block;
164-
}
165-
166-
.copy-action {
167-
right: 0px;
168-
color: #409eff;
169-
}
170-
171-
&.copying {
172-
transform: translateX(-44px);
173-
}
174-
175-
.copy-action-success {
176-
color: #f5222d;
177-
}
178-
179-
&:hover {
180-
color: #409eff;
181-
background-color: #f9fafc;
182-
}
183-
& .text-slide-enter,
184-
& .text-slide-leave-active {
185-
opacity: 0;
186-
transform: translateX(10px);
187-
}
188-
189-
& .bounce-enter-active {
190-
animation: bounce-in 0.5s;
191-
}
192-
193-
@keyframes bounce-in {
194-
0% {
195-
transform: scale(0);
196-
}
197-
50% {
198-
transform: scale(1.5);
199-
}
200-
100% {
201-
transform: scale(1);
202-
}
203-
}
204-
205-
.control-button {
206-
line-height: 26px;
207-
position: absolute;
208-
top: 0;
209-
right: 0;
210-
font-size: 14px;
211-
padding-left: 5px;
212-
padding-right: 25px;
213-
}
214-
}
215-
}
216-
</style>
217-
21844
<script type="text/babel">
219-
import compoLang from './i18n/lang.json';
45+
import './style/index.less'
46+
import defaultLang from './i18n/default_lang.json';
22047
export default {
22148
data() {
22249
return {
@@ -228,9 +55,20 @@ export default {
22855
scrollParent: null
22956
};
23057
},
58+
props: {
59+
options: {
60+
type: Object,
61+
default: () => {
62+
return {}
63+
}
64+
}
65+
},
23166
computed: {
67+
compoLang() {
68+
return this.options.locales || defaultLang
69+
},
23270
langConfig() {
233-
return compoLang.filter(config => config.lang === this.$lang)[0]['demo-block'];
71+
return this.compoLang.filter(config => config.lang === this.$lang)[0]['demo-block'];
23472
},
23573
blockClass() {
23674
return `demo-${this.$lang} demo-${this.$router.currentRoute.path

src/common/containers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = options => {
1717
if (tokens[idx].nesting === 1) {
1818
const description = m && m.length > 1 ? m[1] : '';
1919
const content = tokens[idx + 1].type === 'fence' ? tokens[idx + 1].content : '';
20-
return `<${componentName}>
20+
const encodeOptionsStr = encodeURI(JSON.stringify(options));
21+
return `<${componentName} :options="JSON.parse(decodeURI('${encodeOptionsStr}'))">
2122
<template slot="demo"><!--pre-render-demo:${content}:pre-render-demo--></template>
2223
${description ? `<div slot="description">${md.render(description).html}</div>` : ''}
2324
<template slot="source">

src/i18n/default_lang.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"lang": "zh-CN",
4+
"demo-block": {
5+
"hide-text": "隐藏代码",
6+
"show-text": "显示代码",
7+
"copy-text": "复制代码",
8+
"copy-success": "复制成功"
9+
}
10+
},
11+
{
12+
"lang": "en-US",
13+
"demo-block": {
14+
"hide-text": "Hide",
15+
"show-text": "Expand",
16+
"copy-text": "Copy",
17+
"copy-success": "Successful"
18+
}
19+
}
20+
]

0 commit comments

Comments
 (0)