Skip to content

Commit fe77864

Browse files
authored
Convert Esperanto locale to TypeScript (#2885)
1 parent a255692 commit fe77864

File tree

10 files changed

+244
-208
lines changed

10 files changed

+244
-208
lines changed

src/locale/_lib/buildFormatLongFn/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { FormatLongFn, FormatLongWidth } from '../../types'
22

3-
export interface BuildFormatLongFnArgs {
4-
formats: { [format in FormatLongWidth]: string }
5-
defaultWidth: FormatLongWidth
3+
export interface BuildFormatLongFnArgs<
4+
DefaultMatchWidth extends FormatLongWidth
5+
> {
6+
formats: Partial<{ [format in FormatLongWidth]: string }> &
7+
{ [format in DefaultMatchWidth]: string }
8+
defaultWidth: DefaultMatchWidth
69
}
710

8-
export default function buildFormatLongFn(
9-
args: BuildFormatLongFnArgs
10-
): FormatLongFn {
11+
export default function buildFormatLongFn<
12+
DefaultMatchWidth extends FormatLongWidth
13+
>(args: BuildFormatLongFnArgs<DefaultMatchWidth>): FormatLongFn {
1114
return (options = {}) => {
1215
// TODO: Remove String()
1316
const width = options.width

src/locale/eo/_lib/formatDistance/index.js

Lines changed: 0 additions & 101 deletions
This file was deleted.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import type { FormatDistanceFn, FormatDistanceLocale } from '../../../types'
2+
3+
type FormatDistanceTokenValue =
4+
| string
5+
| {
6+
one: string
7+
other: string
8+
}
9+
10+
const formatDistanceLocale: FormatDistanceLocale<FormatDistanceTokenValue> = {
11+
lessThanXSeconds: {
12+
one: 'malpli ol sekundo',
13+
other: 'malpli ol {{count}} sekundoj',
14+
},
15+
16+
xSeconds: {
17+
one: '1 sekundo',
18+
other: '{{count}} sekundoj',
19+
},
20+
21+
halfAMinute: 'duonminuto',
22+
23+
lessThanXMinutes: {
24+
one: 'malpli ol minuto',
25+
other: 'malpli ol {{count}} minutoj',
26+
},
27+
28+
xMinutes: {
29+
one: '1 minuto',
30+
other: '{{count}} minutoj',
31+
},
32+
33+
aboutXHours: {
34+
one: 'proksimume 1 horo',
35+
other: 'proksimume {{count}} horoj',
36+
},
37+
38+
xHours: {
39+
one: '1 horo',
40+
other: '{{count}} horoj',
41+
},
42+
43+
xDays: {
44+
one: '1 tago',
45+
other: '{{count}} tagoj',
46+
},
47+
48+
aboutXMonths: {
49+
one: 'proksimume 1 monato',
50+
other: 'proksimume {{count}} monatoj',
51+
},
52+
53+
xWeeks: {
54+
one: '1 semajno',
55+
other: '{{count}} semajnoj',
56+
},
57+
58+
aboutXWeeks: {
59+
one: 'proksimume 1 semajno',
60+
other: 'proksimume {{count}} semajnoj',
61+
},
62+
63+
xMonths: {
64+
one: '1 monato',
65+
other: '{{count}} monatoj',
66+
},
67+
68+
aboutXYears: {
69+
one: 'proksimume 1 jaro',
70+
other: 'proksimume {{count}} jaroj',
71+
},
72+
73+
xYears: {
74+
one: '1 jaro',
75+
other: '{{count}} jaroj',
76+
},
77+
78+
overXYears: {
79+
one: 'pli ol 1 jaro',
80+
other: 'pli ol {{count}} jaroj',
81+
},
82+
83+
almostXYears: {
84+
one: 'preskaŭ 1 jaro',
85+
other: 'preskaŭ {{count}} jaroj',
86+
},
87+
}
88+
89+
const formatDistance: FormatDistanceFn = (token, count, options) => {
90+
let result
91+
92+
const tokenValue = formatDistanceLocale[token]
93+
if (typeof tokenValue === 'string') {
94+
result = tokenValue
95+
} else if (count === 1) {
96+
result = tokenValue.one
97+
} else {
98+
result = tokenValue.other.replace('{{count}}', String(count))
99+
}
100+
101+
if (options?.addSuffix) {
102+
if (options?.comparison && options.comparison > 0) {
103+
return 'post ' + result
104+
} else {
105+
return 'antaŭ ' + result
106+
}
107+
}
108+
109+
return result
110+
}
111+
112+
export default formatDistance
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index'
2+
import type { FormatLong } from '../../../types'
23

3-
var dateFormats = {
4+
const dateFormats = {
45
full: "EEEE, do 'de' MMMM y",
56
long: 'y-MMMM-dd',
67
medium: 'y-MMM-dd',
7-
short: 'yyyy-MM-dd'
8+
short: 'yyyy-MM-dd',
89
}
910

10-
var timeFormats = {
11+
const timeFormats = {
1112
full: "Ho 'horo kaj' m:ss zzzz",
1213
long: 'HH:mm:ss z',
1314
medium: 'HH:mm:ss',
14-
short: 'HH:mm'
15+
short: 'HH:mm',
1516
}
1617

17-
var dateTimeFormats = {
18-
any: '{{date}} {{time}}'
18+
const dateTimeFormats = {
19+
any: '{{date}} {{time}}',
1920
}
2021

21-
var formatLong = {
22+
const formatLong: FormatLong = {
2223
date: buildFormatLongFn({
2324
formats: dateFormats,
24-
defaultWidth: 'full'
25+
defaultWidth: 'full',
2526
}),
2627

2728
time: buildFormatLongFn({
2829
formats: timeFormats,
29-
defaultWidth: 'full'
30+
defaultWidth: 'full',
3031
}),
3132

3233
dateTime: buildFormatLongFn({
3334
formats: dateTimeFormats,
34-
defaultWidth: 'any'
35-
})
35+
defaultWidth: 'any',
36+
}),
3637
}
3738

3839
export default formatLong

src/locale/eo/_lib/formatRelative/index.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { FormatRelativeFn } from '../../../types'
2+
3+
const formatRelativeLocale = {
4+
lastWeek: "'pasinta' eeee 'je' p",
5+
yesterday: "'hieraŭ je' p",
6+
today: "'hodiaŭ je' p",
7+
tomorrow: "'morgaŭ je' p",
8+
nextWeek: "eeee 'je' p",
9+
other: 'P',
10+
}
11+
12+
const formatRelative: FormatRelativeFn = (token, _date, _baseDate, _options) =>
13+
formatRelativeLocale[token]
14+
15+
export default formatRelative

0 commit comments

Comments
 (0)