Skip to content

Commit b728da5

Browse files
authored
fix: Implement ordinal in Bulgarian translation (fixes #1501) (#1502)
1 parent 0b0c6a3 commit b728da5

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

src/locale/bg.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,23 @@ const locale = {
99
months: 'януари_февруари_март_април_май_юни_юли_август_септември_октомври_ноември_декември'.split('_'),
1010
monthsShort: 'янр_фев_мар_апр_май_юни_юли_авг_сеп_окт_ное_дек'.split('_'),
1111
weekStart: 1,
12-
ordinal: n => `${n}.`,
12+
ordinal: (n) => {
13+
const last2Digits = n % 100
14+
if (last2Digits > 10 && last2Digits < 20) {
15+
return `${n}-ти`
16+
}
17+
18+
const lastDigit = n % 10
19+
if (lastDigit === 1) {
20+
return `${n}-ви`
21+
} else if (lastDigit === 2) {
22+
return `${n}-ри`
23+
} else if (lastDigit === 7 || lastDigit === 8) {
24+
return `${n}-ми`
25+
}
26+
27+
return `${n}-ти`
28+
},
1329
formats: {
1430
LT: 'H:mm',
1531
LTS: 'H:mm:ss',
@@ -27,7 +43,7 @@ const locale = {
2743
h: 'час',
2844
hh: '%d часа',
2945
d: 'ден',
30-
dd: '%d дни',
46+
dd: '%d дена',
3147
M: 'месец',
3248
MM: '%d месеца',
3349
y: 'година',

test/locale/bg.test.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import moment from 'moment'
2+
import MockDate from 'mockdate'
3+
import dayjs from '../../src'
4+
import relativeTime from '../../src/plugin/relativeTime'
5+
import advancedFormat from '../../src/plugin/advancedFormat'
6+
import '../../src/locale/bg'
7+
8+
dayjs.extend(relativeTime)
9+
dayjs.extend(advancedFormat)
10+
11+
beforeEach(() => {
12+
MockDate.set(new Date())
13+
})
14+
15+
afterEach(() => {
16+
MockDate.reset()
17+
})
18+
19+
it('Format Month with locale function', () => {
20+
for (let i = 0; i <= 7; i += 1) {
21+
const dayjsBG = dayjs().locale('bg').add(i, 'day')
22+
const momentBG = moment().locale('bg').add(i, 'day')
23+
const testFormat1 = 'DD MMMM YYYY MMM'
24+
const testFormat2 = 'MMMM'
25+
const testFormat3 = 'MMM'
26+
expect(dayjsBG.format(testFormat1)).toEqual(momentBG.format(testFormat1))
27+
expect(dayjsBG.format(testFormat2)).toEqual(momentBG.format(testFormat2))
28+
expect(dayjsBG.format(testFormat3)).toEqual(momentBG.format(testFormat3))
29+
}
30+
})
31+
32+
it('RelativeTime: Time from X', () => {
33+
const T = [
34+
[44.4, 'second'], // a few seconds
35+
[89.5, 'second'], // a minute
36+
[130, 'second'], // two minutes
37+
[43, 'minute'], // 44 minutes
38+
[1, 'hour'], // 1 hour
39+
[21, 'hour'], // 21 hours
40+
[2, 'day'], // 2 days
41+
[25, 'day'], // 25 days
42+
[2, 'month'], // 2 months
43+
[10, 'month'], // 10 months
44+
[18, 'month'], // 2 years
45+
[15, 'year'] // 15 years
46+
]
47+
48+
T.forEach((t) => {
49+
dayjs.locale('bg')
50+
moment.locale('bg')
51+
expect(dayjs().from(dayjs().add(t[0], t[1])))
52+
.toBe(moment().from(moment().add(t[0], t[1])))
53+
expect(dayjs().from(dayjs().add(t[0], t[1]), true))
54+
.toBe(moment().from(moment().add(t[0], t[1]), true))
55+
})
56+
})
57+
58+
it('Ordinal', () => {
59+
dayjs.locale('bg')
60+
moment.locale('bg')
61+
62+
for (let d = 1; d <= 31; d += 1) {
63+
const day = d < 10 ? `0${d}` : d
64+
const date = `2021-01-${day}`
65+
expect(dayjs(date).format('Do')).toBe(moment(date).format('Do'))
66+
}
67+
})

0 commit comments

Comments
 (0)