Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intl.RelativeTimeFormat and Intl.ListFormat don't work on languages other than English on node 12.10.0 #29525

Closed
9oelM opened this issue Sep 11, 2019 · 2 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. i18n-api Issues and PRs related to the i18n implementation. question Issues that look for answers.

Comments

@9oelM
Copy link

9oelM commented Sep 11, 2019

  • Version:
$ node -v
v12.10.0
  • Platform: Mac OS & Ubuntu
$ uname -a
Darwin username 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
$ uname -a
Linux ip-172-31-90-221 4.15.0-1045-aws #47-Ubuntu SMP Fri Aug 2 13:50:30 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Intro to my problem

I looked at the video from Google IO 2019 that talked about the latest features in javascript, and there was a part on improvement on Intl API and I wanted to try it out myself by using the latest version of node (12.10.0 at this time of writing):

image
image

and I confirmed again that the new features for Intl work on node v.12+ from these articles:

from v8's blog as well.

These are the things I tested on my laptop (mac OS) and also on my AWS EC2 Ubuntu instance (because I wanted to be as objective as possible):

Problem description

Mac OS

$ node
Welcome to Node.js v12.10.0.
Type ".help" for more information.
> const rtf = new Intl.RelativeTimeFormat('ta-in', { numeric: 'auto' })
undefined
>
> rtf.format(-1, 'day')
'yesterday'
> rtf.format(0, 'day')
'today'
> rtf.format(1, 'day')
'tomorrow'
> rtf.format(-1, 'week')
'last week'
> rtf.format(0, 'week')
'this week'
> rtf.format(1, 'week')
'next week'
>
> const lf1 = new Intl.ListFormat('hi-in')
undefined
> lf1.format(['a', 'b'])
'a and b'
> lf1.format(['a', 'b', 'c'])
'a, b, and c'
>
> const lf2 = new Intl.ListFormat('hi-in', { type: 'disjunction'})
undefined
> lf2.format(['a', 'b'])
'a or b'
> lf2.format(['a', 'b', 'c'])
'a, b, or c'

Ubuntu 18.04

ubuntu:~/environment $ node
Welcome to Node.js v12.10.0.
Type ".help" for more information.
> const rtf = new Intl.RelativeTimeFormat('ta-in', { numeric: 'auto' })
undefined
> 
> rtf.format(-1, 'day')
'yesterday'
> rtf.format(0, 'day')
'today'
> rtf.format(1, 'day')
'tomorrow'
> rtf.format(-1, 'week')
'last week'
> rtf.format(0, 'week')
'this week'
> rtf.format(1, 'week')
'next week'
> 
> const lf1 = new Intl.ListFormat('hi-in')
undefined
> lf1.format(['a', 'b'])
'a and b'
> lf1.format(['a', 'b', 'c'])
'a, b, and c'
> 
> const lf2 = new Intl.ListFormat('hi-in', { type: 'disjunction'})
undefined
> lf2.format(['a', 'b'])
'a or b'
> lf2.format(['a', 'b', 'c'])
'a, b, or c'
> 

Chrome 76 (on my mac)

const rtf = new Intl.RelativeTimeFormat('ta-in', { numeric: 'auto' })
console.log(
rtf.format(-1, 'day'),
rtf.format(0, 'day'),
rtf.format(1, 'day'),
rtf.format(-1, 'week'),
rtf.format(0, 'week'),
rtf.format(1, 'week'))

const lf1 = new Intl.ListFormat('hi-in')
console.log(
lf1.format(['a', 'b']),
lf1.format(['a', 'b', 'c']))

const lf2 = new Intl.ListFormat('hi-in', { type: 'disjunction'})
console.log(
lf2.format(['a', 'b']),
lf2.format(['a', 'b', 'c']))

// result
vendors~main.257badf6.chunk.js:38 நேற்று இன்று நாளை கடந்த வாரம் இந்த வாரம் அடுத்த வாரம்
vendors~main.257badf6.chunk.js:38 a और b a, b, और c
vendors~main.257badf6.chunk.js:38 a या b a, b या c

FYI, I used the code snippets from Google IO 2019 to avoid writing stupid things by mistake. Yeap. As you can see, Chrome 76 perfectly outputs what's expected, while node repl on both operating systems did not work as expected. They only give outputs in English, which I think is a default fallback option.

If this is real, I think it is a huge error, so I am still in a big doubt thinking if node v.12+ really supports these features. Is this really a bug?!??

@devsnek
Copy link
Member

devsnek commented Sep 11, 2019

By default node only ships with a small subset of internationalization data. We are planning to increase the internationalization data available in future releases. You can watch #29522 for more information on that. On current versions of node, https://nodejs.org/api/intl.html has information on how to build node with full intl data or load it at runtime.

@devsnek devsnek added duplicate Issues and PRs that are duplicates of other issues or PRs. question Issues that look for answers. i18n-api Issues and PRs related to the i18n implementation. labels Sep 11, 2019
@9oelM
Copy link
Author

9oelM commented Sep 11, 2019

@devsnek thanks for the clarification. Closing it!

@9oelM 9oelM closed this as completed Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. i18n-api Issues and PRs related to the i18n implementation. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants