Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 278a798

Browse files
author
lei
committed
feat: 🎸 添加模式定义的翻译
1 parent 38e37b9 commit 278a798

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎src/components/Pattern.jsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { patterns } from '../static/patterns';
1111
import { restart } from '../actions/restart';
1212
import { getMode } from '../selectors';
1313
import { withTranslation } from 'react-i18next';
14+
import i18n from '../i18n';
1415

1516

1617
SyntaxHighlighter.registerLanguage('javascript', js);
@@ -50,17 +51,32 @@ const StyledLink = styled(Link)`
5051
}
5152
`;
5253

54+
const createProxy = (pattern) => new Proxy(pattern, {
55+
get(target, key, receiver) {
56+
let localeValue = target[key + '_' + i18n.language];
57+
let value = target[key];
58+
return localeValue ? localeValue : value;
59+
}
60+
});
61+
5362
class Pattern extends React.Component {
5463
componentDidMount() {
5564
this.props.reset();
5665
}
5766

67+
pattern
68+
5869
render() {
5970
const {
6071
params: { id }
6172
} = this.props.match;
6273

63-
const pattern = patterns.filter(item => item.id === id)[0];
74+
if (!this.pattern) {
75+
const p = patterns.filter(item => item.id === id)[0];
76+
this.pattern = createProxy(p);
77+
}
78+
79+
const pattern = this.pattern;
6480

6581
const style = this.props.mode === 'dark' ? styleDark : styleLight;
6682

‎src/static/patterns/behavioral_command.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ const COMMAND = {
55
hint: 'Encapsulate a command request as an object',
66
definition: `Encapsulate a request as an object, thereby letting you parameterize clients with different requests,
77
queue or log requests, and support undoable operations.`,
8+
definition_zh: `将请求封装为对象,从而允许您参数化具有不同请求的客户端,在队列中记录请求,并支持可撤消的操作。`,
89
when:
910
'you have a queue of requests to handle or you want to log them. Also when you want to have an «undo» action',
11+
when_zh:
12+
'您有一个请求队列要处理,或者想要记录它们。再或者,您想要执行"撤消"操作。比如:计算器,文章编辑等',
1013
codeES5: `function Cockpit(instruction) {
1114
this.instruction = instruction;
1215
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /