nodejs/Intl

[Discussion] Locale negotiation between client-server

caridy opened this issue · 6 comments

As today, negotiation is happening in user-land, most people are using negotiator, which is powering express and other popular frameworks. It allows to compute the list of locales that most likely fit a particular request based on the request information. e.g.:

https://github.com/jshttp/negotiator#accept-language-negotiation

We need to consolidate this, and get the different WG to weight in on this matter, and see if we should have a low level (core) feature to support this negotiation.

#27 is for documentation of this.

I have not tested negotiator but the API looks right.

Proof of concept: https://github.com/srl295/localilator
Instance: https://localilator.mybluemix.net

When run locally, I can get output like:

Today: lunes, 1 de febrero de 2016
Visitor: 1
es-es

or with some tweaking:

Today: วันจันทร์ที่ ๑ กุมภาพันธ์ ๒๕๕๙
Visitor: ๑๒
th-u-nu-thai

Sample code:

http.createServer(function(req, res) {
    var l = localilator(req);

  res.end('Today: ' + l.date({month:"long",}).format(new Date()) + '\n'
      +'Visitor: ' + l.number({}).format(++visitor) + '\n'

the "full-icu" is not working right now, so I don't have a live demo to try.

awesome, but we should bikeshed on localilator, I can't even pronounce that! :)

I need to check negotiator itself here, but I filed these bugs against parsers not handling bcp47 script correctly:

As part of Project Fluent we've designed a locale manipulation library that is similar to proposed Intl.Locale and does negotiation on top of it:

Trott commented

Closing due to inactivity. Feel free to pick this up again in the main nodejs/node repo (or any nodejs repo that seems appropriate). This one will probably be read-only soon.