Skip to content

Commit 315abe8

Browse files
authored
[locale] br: Add meridiem translation and correct quotemark (#5433)
1 parent 22bf4ca commit 315abe8

File tree

2 files changed

+122
-21
lines changed

2 files changed

+122
-21
lines changed

src/locale/br.js

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,72 @@ function softMutation(text) {
4848
return mutationTable[text.charAt(0)] + text.substring(1);
4949
}
5050

51+
var monthsParse = [
52+
/^gen/i,
53+
/^c[ʼ\']hwe/i,
54+
/^meu/i,
55+
/^ebr/i,
56+
/^mae/i,
57+
/^(mez|eve)/i,
58+
/^gou/i,
59+
/^eos/i,
60+
/^gwe/i,
61+
/^her/i,
62+
/^du/i,
63+
/^ker/i,
64+
],
65+
monthsRegex = /^(genver|c[ʼ\']hwevrer|meurzh|ebrel|mae|mezheven|gouere|eost|gwengolo|here|du|kerzu|gen|c[ʼ\']hwe|meu|ebr|mae|eve|gou|eos|gwe|her|du|ker)/i,
66+
monthsStrictRegex = /^(genver|c[ʼ\']hwevrer|meurzh|ebrel|mae|mezheven|gouere|eost|gwengolo|here|du|kerzu)/i,
67+
monthsShortStrictRegex = /^(gen|c[ʼ\']hwe|meu|ebr|mae|eve|gou|eos|gwe|her|du|ker)/i,
68+
fullWeekdaysParse = [
69+
/^sul/i,
70+
/^lun/i,
71+
/^meurzh/i,
72+
/^merc[ʼ\']her/i,
73+
/^yaou/i,
74+
/^gwener/i,
75+
/^sadorn/i,
76+
],
77+
shortWeekdaysParse = [
78+
/^Sul/i,
79+
/^Lun/i,
80+
/^Meu/i,
81+
/^Mer/i,
82+
/^Yao/i,
83+
/^Gwe/i,
84+
/^Sad/i,
85+
],
86+
minWeekdaysParse = [
87+
/^Su/i,
88+
/^Lu/i,
89+
/^Me([^r]|$)/i,
90+
/^Mer/i,
91+
/^Ya/i,
92+
/^Gw/i,
93+
/^Sa/i,
94+
];
95+
5196
export default moment.defineLocale('br', {
52-
months: "Genver_C'hwevrer_Meurzh_Ebrel_Mae_Mezheven_Gouere_Eost_Gwengolo_Here_Du_Kerzu".split(
97+
months: 'Genver_Cʼhwevrer_Meurzh_Ebrel_Mae_Mezheven_Gouere_Eost_Gwengolo_Here_Du_Kerzu'.split(
5398
'_'
5499
),
55-
monthsShort: "Gen_C'hwe_Meu_Ebr_Mae_Eve_Gou_Eos_Gwe_Her_Du_Ker".split('_'),
56-
weekdays: "Sul_Lun_Meurzh_Merc'her_Yaou_Gwener_Sadorn".split('_'),
100+
monthsShort: 'Gen_Cʼhwe_Meu_Ebr_Mae_Eve_Gou_Eos_Gwe_Her_Du_Ker'.split('_'),
101+
weekdays: 'Sul_Lun_Meurzh_Mercʼher_Yaou_Gwener_Sadorn'.split('_'),
57102
weekdaysShort: 'Sul_Lun_Meu_Mer_Yao_Gwe_Sad'.split('_'),
58103
weekdaysMin: 'Su_Lu_Me_Mer_Ya_Gw_Sa'.split('_'),
59-
weekdaysParseExact: true,
104+
weekdaysParse: minWeekdaysParse,
105+
fullWeekdaysParse: fullWeekdaysParse,
106+
shortWeekdaysParse: shortWeekdaysParse,
107+
minWeekdaysParse: minWeekdaysParse,
108+
109+
monthsRegex: monthsRegex,
110+
monthsShortRegex: monthsRegex,
111+
monthsStrictRegex: monthsStrictRegex,
112+
monthsShortStrictRegex: monthsShortStrictRegex,
113+
monthsParse: monthsParse,
114+
longMonthsParse: monthsParse,
115+
shortMonthsParse: monthsParse,
116+
60117
longDateFormat: {
61118
LT: 'HH:mm',
62119
LTS: 'HH:mm:ss',
@@ -67,15 +124,15 @@ export default moment.defineLocale('br', {
67124
},
68125
calendar: {
69126
sameDay: '[Hiziv da] LT',
70-
nextDay: "[Warc'hoazh da] LT",
127+
nextDay: '[Warcʼhoazh da] LT',
71128
nextWeek: 'dddd [da] LT',
72-
lastDay: "[Dec'h da] LT",
129+
lastDay: '[Decʼh da] LT',
73130
lastWeek: 'dddd [paset da] LT',
74131
sameElse: 'L',
75132
},
76133
relativeTime: {
77134
future: 'a-benn %s',
78-
past: "%s 'zo",
135+
past: '%s ʼzo',
79136
s: 'un nebeud segondennoù',
80137
ss: '%d eilenn',
81138
m: 'ur vunutenn',
@@ -98,4 +155,11 @@ export default moment.defineLocale('br', {
98155
dow: 1, // Monday is the first day of the week.
99156
doy: 4, // The week that contains Jan 4th is the first week of the year.
100157
},
158+
meridiemParse: /a.m.|g.m./, // goude merenn | a-raok merenn
159+
isPM: function (token) {
160+
return token === 'g.m.';
161+
},
162+
meridiem: function (hour, minute, isLower) {
163+
return hour < 12 ? 'a.m.' : 'g.m.';
164+
},
101165
});

src/test/locale/br.js

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import moment from '../../moment';
44
localeModule('br');
55

66
test('parse', function (assert) {
7-
var tests = "Genver Gen_C'hwevrer C'hwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker".split(
7+
var tests = 'Genver Gen_Cʼhwevrer Cʼhwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker'.split(
88
'_'
99
),
10-
i;
10+
i,
11+
monthsWithRegularQuoteMark = ["C'hwevrer", "C'hwe"];
12+
1113
function equalTest(input, mmm, i) {
1214
assert.equal(
1315
moment(input, mmm).month(),
@@ -42,17 +44,52 @@ test('parse', function (assert) {
4244
equalTestStrict(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
4345
equalTestStrict(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
4446
}
47+
48+
// check with regular quote mark
49+
equalTest(monthsWithRegularQuoteMark[0], 'MMM', 1);
50+
equalTest(monthsWithRegularQuoteMark[1], 'MMM', 1);
51+
equalTest(monthsWithRegularQuoteMark[0], 'MMMM', 1);
52+
equalTest(monthsWithRegularQuoteMark[1], 'MMMM', 1);
53+
equalTest(monthsWithRegularQuoteMark[0].toLocaleLowerCase(), 'MMM', 1);
54+
equalTest(monthsWithRegularQuoteMark[1].toLocaleLowerCase(), 'MMM', 1);
55+
equalTest(monthsWithRegularQuoteMark[0].toLocaleUpperCase(), 'MMMM', 1);
56+
equalTest(monthsWithRegularQuoteMark[1].toLocaleUpperCase(), 'MMMM', 1);
57+
58+
assert.notEqual(
59+
moment(monthsWithRegularQuoteMark[0], 'MMM', true).month(),
60+
1
61+
);
62+
equalTestStrict(monthsWithRegularQuoteMark[1], 'MMM', 1);
63+
equalTest(monthsWithRegularQuoteMark[0], 'MMMM', 1);
64+
assert.notEqual(
65+
moment(monthsWithRegularQuoteMark[1], 'MMMM', true).month(),
66+
1
67+
);
68+
equalTest(monthsWithRegularQuoteMark[1].toLocaleLowerCase(), 'MMM', 1);
69+
equalTest(monthsWithRegularQuoteMark[0].toLocaleUpperCase(), 'MMMM', 1);
70+
71+
// check weekday with regular quote mark
72+
assert.equal(
73+
moment("merc'her", 'dddd', true).day(),
74+
3,
75+
"merc'her (regular quote)"
76+
);
77+
assert.equal(
78+
moment('mercʼher', 'dddd', true).day(),
79+
3,
80+
'mercʼher (special quote)'
81+
);
4582
});
4683

4784
test('format', function (assert) {
4885
moment.locale('br');
4986
var a = [
5087
[
5188
'dddd, MMMM Do YYYY, h:mm:ss a',
52-
"Sul, C'hwevrer 14vet 2010, 3:25:50 pm",
89+
'Sul, Cʼhwevrer 14vet 2010, 3:25:50 g.m.',
5390
],
54-
['ddd, h A', 'Sul, 3 PM'],
55-
['M Mo MM MMMM MMM', "2 2vet 02 C'hwevrer C'hwe"],
91+
['ddd, h A', 'Sul, 3 g.m.'],
92+
['M Mo MM MMMM MMM', '2 2vet 02 Cʼhwevrer Cʼhwe'],
5693
['YYYY YY', '2010 10'],
5794
['D Do DD', '14 14vet 14'],
5895
['d do dddd ddd dd', '0 0vet Sul Sul Su'],
@@ -64,9 +101,9 @@ test('format', function (assert) {
64101
['s ss', '50 50'],
65102
['DDDo [devezh] [ar] [vloaz]', '45vet devezh ar vloaz'],
66103
['L', '14/02/2010'],
67-
['LL', "14 a viz C'hwevrer 2010"],
68-
['LLL', "14 a viz C'hwevrer 2010 15:25"],
69-
['LLLL', "Sul, 14 a viz C'hwevrer 2010 15:25"],
104+
['LL', '14 a viz Cʼhwevrer 2010'],
105+
['LLL', '14 a viz Cʼhwevrer 2010 15:25'],
106+
['LLLL', 'Sul, 14 a viz Cʼhwevrer 2010 15:25'],
70107
],
71108
b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
72109
i;
@@ -115,7 +152,7 @@ test('format ordinal', function (assert) {
115152

116153
test('format month', function (assert) {
117154
moment.locale('br');
118-
var expected = "Genver Gen_C'hwevrer C'hwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker".split(
155+
var expected = 'Genver Gen_Cʼhwevrer Cʼhwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker'.split(
119156
'_'
120157
),
121158
i;
@@ -130,7 +167,7 @@ test('format month', function (assert) {
130167

131168
test('format week', function (assert) {
132169
moment.locale('br');
133-
var expected = "Sul Sul Su_Lun Lun Lu_Meurzh Meu Me_Merc'her Mer Mer_Yaou Yao Ya_Gwener Gwe Gw_Sadorn Sad Sa".split(
170+
var expected = 'Sul Sul Su_Lun Lun Lu_Meurzh Meu Me_Mercʼher Mer Mer_Yaou Yao Ya_Gwener Gwe Gw_Sadorn Sad Sa'.split(
134171
'_'
135172
),
136173
i;
@@ -295,14 +332,14 @@ test('suffix', function (assert) {
295332
'a-benn un nebeud segondennoù',
296333
'prefix'
297334
);
298-
assert.equal(moment(0).from(30000), "un nebeud segondennoù 'zo", 'suffix');
335+
assert.equal(moment(0).from(30000), 'un nebeud segondennoù ʼzo', 'suffix');
299336
});
300337

301338
test('now from now', function (assert) {
302339
moment.locale('br');
303340
assert.equal(
304341
moment().fromNow(),
305-
"un nebeud segondennoù 'zo",
342+
'un nebeud segondennoù ʼzo',
306343
'now from now should display as in the past'
307344
);
308345
});
@@ -353,12 +390,12 @@ test('calendar day', function (assert) {
353390
);
354391
assert.equal(
355392
moment(a).add({ d: 1 }).calendar(),
356-
"Warc'hoazh da 12:00",
393+
'Warcʼhoazh da 12:00',
357394
'tomorrow at the same time'
358395
);
359396
assert.equal(
360397
moment(a).subtract({ d: 1 }).calendar(),
361-
"Dec'h da 12:00",
398+
'Decʼh da 12:00',
362399
'yesterday at the same time'
363400
);
364401
});

0 commit comments

Comments
 (0)