Skip to content

Commit a0ab59b

Browse files
authored
Merge pull request #28 from TheSumm/lang-de
German language support
2 parents 3378152 + e97407a commit a0ab59b

File tree

11 files changed

+177
-24
lines changed

11 files changed

+177
-24
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ This is the wrapper component that creates the vertical timeline.
2929

3030
- Props
3131

32-
| name | Type | Required | Values Allowed | default values | Description |
33-
| ---------- | ------ | -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
34-
| theme | object | false | colors | { yearColor: "#888888", lineColor: "#c5c5c5", dotColor: "#c5c5c5", borderDotColor: "#ffffff", titleColor: "#cccccc", subtitleColor: "#888888", textColor: "#cccccc" } | Set colors in all components |
35-
| lang | node | false | `en` or `es` | `en` | Change the language `from` and `to` texts and change the format in the dates |
36-
| dateFormat | string | false | `L`, `l` or `ll` | `L` | Change the presentation format of dates |
32+
| name | Type | Required | Values Allowed | default values | Description |
33+
| ---------- | ------ | -------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
34+
| theme | object | false | colors | { yearColor: "#888888", lineColor: "#c5c5c5", dotColor: "#c5c5c5", borderDotColor: "#ffffff", titleColor: "#cccccc", subtitleColor: "#888888", textColor: "#cccccc" } | Set colors in all components |
35+
| lang | node | false | `en`, `es` or `de` | `en` | Change the language `from` and `to` texts and change the format in the dates |
36+
| dateFormat | string | false | `L`, `l` or `ll` | `L` | Change the presentation format of dates |
3737

3838
`dateFormat`: Receive only one of three options. (The options are same the [moment.js](https://momentjs.com/) using).
3939

40-
- The option `L` will return a date like `MM/DD/YYYY` (in english) or `DD/MM/YYYY` (in spanish).
41-
- The option `l` will return a date like `M/D/YYYY` (in english) or `D/M/YYYY` (in spanish).
42-
- The option `ll` will return a date like `MMM DD, YYYY` (in english) or `DD de MMM, YYYY` (in spanish).
40+
- The option `L` will return a date like `MM/DD/YYYY` (in English), `DD/MM/YYYY` (in Spanish) `DD.MM.YYYY` (in German).
41+
- The option `l` will return a date like `M/D/YYYY` (in English), `D/M/YYYY` (in Spanish) `D.M.YYYY` (in German).
42+
- The option `ll` will return a date like `MMM DD, YYYY` (in English), `DD de MMM, YYYY` (in Spanish) `DD. MMM YYYY` (in German).
4343

4444
### Container
4545

src/components/timeline/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Timeline.defaultProps = {
3535

3636
Timeline.propTypes = {
3737
theme: shape({}),
38-
lang: oneOf(['es', 'en']),
38+
lang: oneOf(['es', 'en', 'de']),
3939
dateFormat: oneOf(['L', 'l', 'll']),
4040
children: oneOfType([arrayOf(node), node]).isRequired,
4141
};

src/config/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ export const monthArray = {
4141
'Nov',
4242
'Dec',
4343
],
44+
de: [
45+
'Jan.',
46+
'Feb.',
47+
'März',
48+
'Apr.',
49+
'Mai.',
50+
'Juni',
51+
'Juli',
52+
'Aug.',
53+
'Sep.',
54+
'Okt.',
55+
'Nov.',
56+
'Dez.',
57+
],
4458
};
4559

4660
export const mapText = {
@@ -52,4 +66,8 @@ export const mapText = {
5266
from: 'Desde',
5367
to: 'Hasta',
5468
},
69+
de: {
70+
from: 'Von',
71+
to: 'Bis',
72+
},
5573
};

src/helpers/transform-date.helper.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,39 @@ export const transformDate = ({ date, lang, type }) => {
1616
? `${month ? `${completeWith0(month)}/` : ''}${
1717
day ? `${completeWith0(day)}/` : ''
1818
}${year}`
19-
: `${day ? `${completeWith0(day)}/` : ''}${
19+
: lang === 'es'
20+
? `${day ? `${completeWith0(day)}/` : ''}${
2021
month ? `${completeWith0(month)}/` : ''
21-
}${year}`;
22+
}${year}`
23+
: /* lang === 'de' */
24+
`${
25+
day && month
26+
? `${completeWith0(day)}.${completeWith0(month)}.${year}`
27+
: `${month ? `${completeWith0(month)}/` : ''}${year}`
28+
}`;
2229
case 'l':
2330
return lang === 'en'
2431
? `${month ? `${month}/` : ''}${day ? `${day}/` : ''}${year}`
25-
: `${day ? `${day}/` : ''}${month ? `${month}/` : ''}${year}`;
32+
: lang === 'es'
33+
? `${day ? `${day}/` : ''}${month ? `${month}/` : ''}${year}`
34+
: /* lang === 'de' */
35+
`${
36+
day && month
37+
? `${day}.${month}.${year}`
38+
: `${month ? `${month}/` : ''}${year}`
39+
}`;
2640
case 'll':
2741
return lang === 'en'
2842
? `${month ? `${monthArray[lang][month - 1]}` : ''}${
2943
day ? ` ${completeWith0(day)}` : ''
3044
}${day || month ? ', ' : ''}${year}`
31-
: `${day ? `${day} de ` : ''}${
45+
: lang === 'es'
46+
? `${day ? `${day} de ` : ''}${
3247
month ? `${monthArray[lang][month - 1]}, ` : ''
48+
}${year}`
49+
: /* lang === 'de' */
50+
`${day ? `${day}. ` : ''}${
51+
month ? `${monthArray[lang][month - 1]} ` : ''
3352
}${year}`;
3453
}
3554
};
@@ -45,4 +64,9 @@ export const mapDate = {
4564
l: (date) => transformDate({ date, lang: 'es', type: 'l' }),
4665
ll: (date) => transformDate({ date, lang: 'es', type: 'll' }),
4766
},
67+
de: {
68+
L: (date) => transformDate({ date, lang: 'de', type: 'L' }),
69+
l: (date) => transformDate({ date, lang: 'de', type: 'l' }),
70+
ll: (date) => transformDate({ date, lang: 'de', type: 'll' }),
71+
},
4872
};

test/components/__snapshots__/container.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
exports[`<Container /> should create Snapshot 1`] = `
44
<section
5-
className="sc-AxiKw eozVxv"
5+
className="sc-dlfnbm cWAGMS"
66
>
77
<div>
88
First child
99
</div>
1010
<div
11-
className="sc-AxhCb ccMvAG"
11+
className="sc-hKgILt"
1212
>
1313
<div>
1414
Second child

test/components/__snapshots__/description.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`<Description /> should create Snapshot 1`] = `
44
<li
5-
className="sc-fzoLsD gWtHBF"
5+
className="sc-jrAGrp erWYBT"
66
>
77
text
88
</li>

test/components/__snapshots__/section.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
exports[`<Section /> should create Snapshot 1`] = `
44
<article
5-
className="sc-AxheI kdvXAR"
5+
className="sc-gKsewC eXtzIU"
66
>
77
<p
8-
className="sc-Axmtr kHDhOq"
8+
className="sc-iBPRYJ eQfaEM"
99
>
1010
title
1111
</p>
1212
<ul
13-
className="sc-AxmLO chzFoG"
13+
className="sc-fubCfw eTAXIs"
1414
>
1515
<div>
1616
children

test/components/__snapshots__/timeline.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
exports[`<Timeline /> should create Snapshot 1`] = `
44
<div
5-
className="sc-AxjAm bXdGBi"
5+
className="sc-bdfBwQ iNuYTL"
66
>
77
<div
8-
className="sc-AxirZ lhnuda"
8+
className="sc-gsTCUz fONLjA"
99
>
1010
<div>
1111
Child

test/components/__snapshots__/year-content.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
exports[`<YearContent /> should create Snapshot 1`] = `
44
<p
5-
className="sc-AxhUy hwimqV"
5+
className="sc-eCssSg eJxYfY"
66
format="L"
77
lang="en"
88
>
99
<span
10-
className="sc-AxgMl jZSFGj"
10+
className="sc-jSgupP hSlCmR"
1111
>
1212
From
1313
</span>

test/components/year-content.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('<YearContent />', () => {
4242
expect(wrapper.find('span').text()).toEqual('From');
4343

4444
expect(wrapper.find('time')).toHaveLength(2);
45-
expect(wrapper.find('time').text().includes('2020')).toBeTruthy();
45+
expect(wrapper.find('time').text().includes('2021')).toBeTruthy();
4646
expect(wrapper.find('time').text().includes('08/21/2019')).toBeTruthy();
4747
});
4848

0 commit comments

Comments
 (0)