Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 6c49ca5

Browse files
committed
Properly pretty-print selectordinal arguments
Fixes #44
1 parent 42f3404 commit 6c49ca5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/print-icu-message.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function printICUMessage(ast) {
3030
return `{${node.id}}`;
3131
}
3232

33-
switch (getArgumentType(node.format.type)) {
33+
switch (getArgumentType(node.format)) {
3434
case 'number':
3535
case 'date':
3636
case 'time':
@@ -46,23 +46,30 @@ function printICUMessage(ast) {
4646
return printedNodes.join('');
4747
}
4848

49-
function getArgumentType(astType) {
50-
return astType.replace(/Format$/, '').toLowerCase();
49+
function getArgumentType(format) {
50+
const {type, ordinal} = format;
51+
52+
// Special-case ordinal plurals to use `selectordinal` instead of `plural`.
53+
if (type === 'pluralFormat' && ordinal) {
54+
return 'selectordinal';
55+
}
56+
57+
return type.replace(/Format$/, '').toLowerCase();
5158
}
5259

5360
function printMessageTextASTNode({value}) {
5461
return value.replace(ESAPE_CHARS_REGEXP, (char) => ESCAPED_CHARS[char]);
5562
}
5663

5764
function printSimpleFormatASTNode({id, format}) {
58-
let argumentType = getArgumentType(format.type);
65+
let argumentType = getArgumentType(format);
5966
let style = format.style ? `, ${format.style}` : '';
6067

6168
return `{${id}, ${argumentType}${style}}`;
6269
}
6370

6471
function printOptionalFormatASTNode({id, format}) {
65-
let argumentType = getArgumentType(format.type);
72+
let argumentType = getArgumentType(format);
6673
let offset = format.offset ? `, offset:${format.offset}` : '';
6774

6875
let options = format.options.map((option) => {

0 commit comments

Comments
 (0)