Comments (12)
OK, I made a fancy v2 label for this. I'll leave the issue open for future development.
from proposal-intl-locale.
ICU supports part of this with addKeyValue, where value is empty. We could allow:
var loc = new Intl.Locale('en-u-ca-gregory', {calendar: ''});
// loc.calendar would return ''
Similar (but harder to implement) could be done with region and script. But I am not sure we would want this - what if you have 'zh-TW' and blindly remove region? It would push user to 'zh' which is simplified version.
I would rather implement minimize and maximize methods, or provide getters for language, script and region.
from proposal-intl-locale.
I'd like to express a strong preference for adding these in v2.
When we promoted the feature to stage 3, this indicated that we are done with it from a design standpoint and are ready to move to implementation. At the same time, we can present this method for a new staged proposal as early as the May TC39 meeting. Maybe it will even ship in browsers at the same time.
I'd like to limit additions to this proposal to things that are absolutely needed otherwise the other aspects of the proposal are broken.
from proposal-intl-locale.
@anba We could add a method for this.
Can you think of a case of needing it in an application? This could help guide the appropriate API shape.
Do you think this is a very core, common need? That would drive its inclusion in this proposal, as opposed to a follow-on proposal.
from proposal-intl-locale.
Can you think of a case of needing it in an application? This could help guide the appropriate API shape.
Java's Locale.Builder allows to clear subtags, but when I was searching for Locale.Builder
uses on GitHub most of the time only test or example code shows up. 😒 So I can't provide a definite use case for this functionality right now.
The mailing list and the design notes for Locale.Builder
also don't provide any insights why Locale.Builder
supports this functionality. Or rather, at least I didn't see any notes when skimming over the documents, but maybe I've just missed it.
Do you think this is a very core, common need? That would drive its inclusion in this proposal, as opposed to a follow-on proposal.
From what I've understood, this proposal aims to provide a minimal API surface for locales (e.g. it doesn't provide access to the variant and privateuse subtags or extension subtags besides some selected keywords for the Unicode extension subtag). And I'm okay with that approach, as long as we keep it extensible to be able to add more functionality in the future when needed. (Insert "Captain Obvious" image here. 😛)
So, if no one else shows up to support this functionality, I wouldn't be mad if we defer it and keep it out of the Locale v1 API.
from proposal-intl-locale.
What would happen if you did:
let loc = new Intl.Locale("sr-Cyrl-SR", {script: ""});
I can imagine this returning sr-SR
.
from proposal-intl-locale.
from proposal-intl-locale.
but the question is - is it useful?
Sure, I share your concern about people using it without understanding the consequences (removing CN
from zh-CN
), but I do see some use cases.
For example, in the language negotiation strategy we're using at Mozilla, one of the steps is to compare the list of available locales against the requested locale with some subtags cleared (in order to be treated as a range - en-*
). We currently have private methods like locale.clearRegion()
or locale.clearVariants()
and once we switch to this API, I'd use the provided example to achieve the same.
Here's the documentation of our algorithm - https://searchfox.org/mozilla-central/source/intl/locale/LocaleService.cpp#378
from proposal-intl-locale.
Hmm, actually, I think that minimize
method would work even better here. So I'm totally ok going for that as @nciric suggests instead of some way to remove subtags.
from proposal-intl-locale.
@nciric I like the idea of minimize and maximize methods. Do you think we should do these in v1, or would it be OK to address in a follow-on proposal? As Intl.Locale I'd already at Stage 3, and it doesn't sound like those methods would require any changes to this proposal, just an additional, a follow-on proposal seems procedurally easier.
from proposal-intl-locale.
@littledan - what would be a product of minimize and maximize methods? A new locale object based on minimized/maximized form? Or just a locale string, that can be used to create new Locale object?
Either way, ICU provides trivial way of implementing both, so from that standpoint it can be part of v1.
We just need to make sure to curb feature creep into locale v1 - otherwise we'll never be done (just look at number of methods in ICU u_loc).
from proposal-intl-locale.
a new Locale object imho.
from proposal-intl-locale.
Related Issues (20)
- Modified CanonicalizeLocaleList does not accept Intl.Locale instances when provided as the only argument HOT 1
- Using Unicode locale ID vs BCP 47 in our spec HOT 51
- Resolved value for Unicode extension values when "true" is removed? HOT 4
- Simplified the change to 2.1 CanonicalizeLocaleList HOT 3
- Docs(MDN) Documentation for Intl.Locale HOT 17
- Does hourCycle exist unconditionally? HOT 3
- Not all RFC 5646 production names updated HOT 3
- Move "get caseFirst" after "get calendar"
- Update references to match current UTS 35 spec HOT 11
- Use `type` production from UTS35
- Directly use unicode_language_id in "get baseName"
- Need to test for SameValue(r.[[kn]], "") in addition to SameValue(r.[[kn]], "true")
- no validation of value of extensions in tag? HOT 8
- CanonicalizeLanguageTag should remove duplicate attributes/keywords in a Unicode extension, consistent with Intl.Locale HOT 6
- Getting the default locale HOT 10
- Drop this proposal in favor of a more general user settings object HOT 6
- Spec is vague regarding internal data structure representation HOT 12
- Canonicalise Unicode extensions options added through ResolveLocale HOT 8
- CanonicalizeUnicodeLocaleId should only perform step 1 of "BCP 47 Language Tag to Unicode BCP 47 Locale Identifier" HOT 3
- Archive repository, redirect draft to ecma402 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-intl-locale.