Skip to content

Commit e3b7df0

Browse files
committed
feat: add german translation
1 parent b45a53a commit e3b7df0

File tree

21 files changed

+384
-352
lines changed

21 files changed

+384
-352
lines changed

core/src/core.vue

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<script>
22
import multiple from './fields/multiple'
3-
import types from './types'
4-
import locale from './locale'
3+
import { Field, Position } from './types'
4+
import { getLocale, defaultItems, Locale } from './locale'
55
import util from './util'
66
7-
const { getLocale, defaultItems, getSuffix, getPrefix } = locale
8-
const { Field } = types
9-
107
export default {
118
name: 'VueCronCore',
129
props: {
@@ -36,19 +33,19 @@ export default {
3633
type: Array,
3734
default: () => {
3835
return [
39-
{ id: 'minute', text: 'Minute', value: [] },
40-
{ id: 'hour', text: 'Hour', value: ['minute'] },
41-
{ id: 'day', text: 'Day', value: ['hour', 'minute'] },
42-
{ id: 'week', text: 'Week', value: ['dayOfWeek', 'hour', 'minute'] },
43-
{ id: 'month', text: 'Month', value: ['day', 'dayOfWeek', 'hour', 'minute'] },
44-
{ id: 'year', text: 'Year', value: ['month', 'day', 'dayOfWeek', 'hour', 'minute'] }
36+
{ id: 'minute', value: [] },
37+
{ id: 'hour', value: ['minute'] },
38+
{ id: 'day', value: ['hour', 'minute'] },
39+
{ id: 'week', value: ['dayOfWeek', 'hour', 'minute'] },
40+
{ id: 'month', value: ['day', 'dayOfWeek', 'hour', 'minute'] },
41+
{ id: 'year', value: ['month', 'day', 'dayOfWeek', 'hour', 'minute'] }
4542
]
4643
}
4744
},
4845
customLocale: {
4946
type: Object,
5047
default: function (props) {
51-
return getLocale(props.locale)
48+
return null
5249
}
5350
},
5451
mergeLocale: {
@@ -95,13 +92,22 @@ export default {
9592
return this.computedFields[i]
9693
})
9794
},
98-
computedLocale () {
95+
_loc () {
9996
if (this.mergeLocale) {
100-
const defaultLocale = getLocale(this.locale)
101-
return util.deepMerge(defaultLocale, this.customLocale)
97+
return getLocale(this.locale, this.customLocale)
10298
} else {
103-
return this.customLocale
99+
return this.customLocale ? new Locale(this.customLocale) : getLocale(this.locale)
100+
}
101+
},
102+
_periods () {
103+
if (!this.periods) {
104+
return []
104105
}
106+
return this.periods.map(p => {
107+
return Object.assign({
108+
text: this._loc.getLocaleStr(p.id, Position.Text)
109+
}, p)
110+
})
105111
}
106112
},
107113
@@ -150,14 +156,25 @@ export default {
150156
})(field.id)
151157
}
152158
159+
const cronSegment = multiple.arrayToStr(values, field)
160+
const segments = Array.isArray(cronSegment.segments) ? cronSegment.segments : [cronSegment]
161+
162+
const selectedStr = segments.map((seg) => {
163+
const params = util.populate(seg, field.itemMap)
164+
params.field = field
165+
return this._loc.render(this.selectedPeriod.id, field.id, seg.type, Position.Text, params)
166+
}).join(',')
167+
const prefix = this._loc.getLocaleStr(this.selectedPeriod.id, field.id, cronSegment.type, Position.Prefix)
168+
const suffix = this._loc.getLocaleStr(this.selectedPeriod.id, field.id, cronSegment.type, Position.Suffix)
169+
153170
fieldProps.push({
154171
...field,
155172
cron: this.splitValue[i],
156-
selectedStr: multiple.arrayToStr(values, field).getText(this.computedLocale, this.selectedPeriod.id),
173+
selectedStr,
157174
events,
158175
attrs,
159-
prefix: getPrefix(this.computedLocale, this.selectedPeriod.id, field.id),
160-
suffix: getSuffix(this.computedLocale, this.selectedPeriod.id, field.id)
176+
prefix,
177+
suffix
161178
})
162179
}
163180
@@ -175,9 +192,9 @@ export default {
175192
this.selectedPeriod = this.periods[i]
176193
}
177194
},
178-
items: this.periods,
179-
prefix: this.computedLocale.periodPrefix,
180-
suffix: this.computedLocale.periodSuffix
195+
items: this._periods,
196+
prefix: this._loc.getLocaleStr(this.selectedPeriod.id, Position.Prefix),
197+
suffix: this._loc.getLocaleStr(this.selectedPeriod.id, Position.Suffix)
181198
}
182199
})
183200
},

core/src/fields/any.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
// *
3-
import types from '../types'
4-
const { AnyColumn } = types
3+
import { AnySegment } from '../types'
54

65
function strToArray (str) {
76
if (str !== '*') {
@@ -14,7 +13,7 @@ function arrayToStr (arr, field) {
1413
const { items } = field
1514

1615
if (arr.length === 0) {
17-
return new AnyColumn(field)
16+
return new AnySegment()
1817
}
1918
if (arr.length !== items.length) {
2019
return null
@@ -25,7 +24,7 @@ function arrayToStr (arr, field) {
2524
return null
2625
}
2726
}
28-
return new AnyColumn(field)
27+
return new AnySegment()
2928
}
3029

3130
export default {

core/src/fields/every.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// */x
2-
import types from '../types'
3-
const { EveryColumn } = types
2+
import { EverySegment } from '../types'
43

54
const re = /^\*\/\d+$/
65

@@ -45,7 +44,7 @@ function arrayToStr (arr, field) {
4544
}
4645
}
4746

48-
return new EveryColumn(field, step)
47+
return new EverySegment(step)
4948
}
5049

5150
export default {

core/src/fields/range.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import types from '../types'
1+
import { CombinedSegment, RangeSegment, ValueSegment } from '../types'
22
import util from '../util'
3-
const { RangeColumn, CombinedColumn, ValueColumn } = types
43
// x-y
54

65
const re = /^\d+-\d+$/
@@ -43,15 +42,15 @@ function arrayToStr (arr, field) {
4342
for (let i = 0; i < arr.length; i++) {
4443
if (arr[i + 1] === undefined || arr[i + 1] - arr[i] > 1) {
4544
if (i === start) {
46-
ranges.push(new ValueColumn(field, arr[start]))
45+
ranges.push(new ValueSegment(arr[start]))
4746
} else {
48-
ranges.push(new RangeColumn(field, arr[start], arr[i]))
47+
ranges.push(new RangeSegment(arr[start], arr[i]))
4948
}
5049
start = i + 1
5150
}
5251
}
5352

54-
return new CombinedColumn(field, ranges)
53+
return new CombinedSegment(ranges)
5554
}
5655

5756
export default {

core/src/fields/value.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// x
2-
import types from '../types'
3-
const { ValueColumn, CombinedColumn } = types
2+
import { CombinedSegment, ValueSegment } from '../types'
43

54
function strToArray (str, { min, max }) {
65
const number = parseInt(str)
@@ -17,8 +16,8 @@ function arrayToStr (arr, field) {
1716
return null
1817
}
1918

20-
const values = arr.map((x) => { return new ValueColumn(field, x) })
21-
return new CombinedColumn(field, values)
19+
const values = arr.map((x) => { return new ValueSegment(x) })
20+
return new CombinedSegment(values)
2221
}
2322

2423
export default {

core/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Import vue component
22
import component from './core.vue'
3-
import locale from './locale'
3+
import * as locale from './locale'
44
import util from './util'
55

66
// Declare install function executed by Vue.use()

core/src/locale/de.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
export default {
2+
'*': {
3+
prefix: 'Jede',
4+
suffix: '',
5+
text: 'Unknown',
6+
'*': {
7+
value: { text: '{{val.text}}' },
8+
range: { text: '{{start.text}}-{{end.text}}' },
9+
everyX: { text: 'alle {{every.value}}' }
10+
},
11+
month: {
12+
'*': { prefix: 'im' },
13+
empty: {
14+
prefix: 'in',
15+
text: 'jedem Monat'
16+
},
17+
value: { text: '{{val.alt}}' },
18+
range: { text: '{{start.alt}}-{{end.alt}}' }
19+
},
20+
day: {
21+
'*': { prefix: 'den' },
22+
empty: {
23+
prefix: 'an',
24+
text: 'jedem Tag'
25+
},
26+
everyX: {
27+
prefix: '',
28+
text: 'alle {{every.value}} Tage'
29+
}
30+
},
31+
dayOfWeek: {
32+
'*': { prefix: 'am' },
33+
empty: {
34+
prefix: 'an',
35+
text: 'jedem Wochentag'
36+
},
37+
value: { text: '{{val.alt}}' },
38+
range: { text: '{{start.alt}}-{{end.alt}}' }
39+
},
40+
hour: {
41+
'*': { prefix: 'um' },
42+
empty: {
43+
prefix: 'zu',
44+
text: 'jeder Stunde'
45+
},
46+
everyX: {
47+
prefix: '',
48+
text: 'alle {{every.value}} Stunden'
49+
}
50+
},
51+
minute: {
52+
'*': { prefix: ':' },
53+
empty: { text: 'jede Minute' },
54+
everyX: {
55+
prefix: '',
56+
text: 'alle {{every.value}} Minuten'
57+
}
58+
}
59+
},
60+
minute: {
61+
text: 'Minute'
62+
},
63+
hour: {
64+
text: 'Stunde',
65+
minute: {
66+
'*': {
67+
prefix: 'zu',
68+
suffix: 'Minute(n)'
69+
},
70+
empty: { text: 'jeder' }
71+
}
72+
},
73+
day: {
74+
prefix: 'Jeden',
75+
text: 'Tag'
76+
},
77+
week: {
78+
text: 'Woche'
79+
},
80+
month: {
81+
prefix: 'Jedes',
82+
text: 'Monat'
83+
84+
},
85+
year: {
86+
prefix: 'Jedes',
87+
text: 'Jahr'
88+
}
89+
}

core/src/locale/en.js

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
11
export default {
2-
eachPeriod: {
3-
eachField: {
4-
empty: 'every {{field.id}}',
5-
value: '{{value.text}}',
6-
range: '{{start.text}}-{{end.text}}',
7-
everyX: 'every {{every.value}}'
2+
'*': {
3+
prefix: 'Every',
4+
suffix: '',
5+
text: 'Unknown',
6+
'*': {
7+
empty: { text: 'every {{field.id}}' },
8+
value: { text: '{{val.text}}' },
9+
range: { text: '{{start.text}}-{{end.text}}' },
10+
everyX: { text: 'every {{every.value}}' }
811
},
9-
monthField: {
10-
prefix: 'in',
11-
value: '{{value.alt}}',
12-
range: '{{start.alt}}-{{end.alt}}'
12+
month: {
13+
'*': { prefix: 'in' },
14+
value: { text: '{{val.alt}}' },
15+
range: { text: '{{start.alt}}-{{end.alt}}' }
1316
},
14-
dayField: {
15-
prefix: 'on'
17+
day: {
18+
'*': { prefix: 'on' }
1619
},
17-
dayOfWeekField: {
18-
prefix: 'on',
19-
empty: 'every day of the week',
20-
value: '{{value.alt}}',
21-
range: '{{start.alt}}-{{end.alt}}'
20+
dayOfWeek: {
21+
'*': { prefix: 'on' },
22+
empty: { text: 'every day of the week' },
23+
value: { text: '{{val.alt}}' },
24+
range: { text: '{{start.alt}}-{{end.alt}}' }
2225
},
23-
hourField: {
24-
prefix: 'at'
26+
hour: {
27+
'*': { prefix: 'at' }
2528
},
26-
minuteField: {
27-
prefix: ':'
29+
minute: {
30+
'*': { prefix: ':' }
2831
}
2932
},
30-
hourPeriod: {
31-
minuteField: {
32-
prefix: 'at',
33-
suffix: 'minute(s)',
34-
empty: 'every'
35-
}
33+
minute: {
34+
text: 'Minute'
3635
},
37-
monthPeriod: {
38-
dayOfWeekField: {
39-
prefix: 'and'
36+
hour: {
37+
text: 'Hour',
38+
minute: {
39+
'*': {
40+
prefix: 'at',
41+
suffix: 'minute(s)'
42+
},
43+
empty: { text: 'every' }
4044
}
4145
},
42-
yearPeriod: {
43-
dayOfWeekField: {
44-
prefix: 'and'
46+
day: {
47+
text: 'Day'
48+
},
49+
week: {
50+
text: 'Week'
51+
},
52+
month: {
53+
text: 'Month',
54+
dayOfWeek: {
55+
'*': { prefix: 'and' }
4556
}
4657
},
47-
periodPrefix: 'Every',
48-
periodSuffix: ''
58+
year: {
59+
text: 'Year',
60+
dayOfWeek: {
61+
'*': { prefix: 'and' }
62+
}
63+
}
4964
}

0 commit comments

Comments
 (0)