-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add regionCode attribute #690
Changes from 5 commits
25bf943
66a1237
8f030ca
8199e35
58e0d95
2febe42
cdd18dc
5f23fac
d1aca5d
1695891
d2b59ee
699d329
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2148,6 +2148,7 @@ <h2> | |
readonly attribute DOMString postalCode; | ||
readonly attribute DOMString recipient; | ||
readonly attribute DOMString region; | ||
readonly attribute DOMString regionCode; | ||
readonly attribute DOMString sortingCode; | ||
readonly attribute FrozenArray<DOMString> addressLine; | ||
}; | ||
|
@@ -2199,6 +2200,75 @@ <h2> | |
</li> | ||
</ol> | ||
</li> | ||
<li>If <var>details</var>["<a>regionCode</a>"] is present and not | ||
the empty string: | ||
<ol> | ||
<li>Let <var>regionCode</var> be the result of <a>strip leading | ||
and trailing ASCII whitespace</a> from | ||
<var>details</var>["<a>regionCode</a>"] and then | ||
<a data-cite="!INFRA#ascii-uppercase">ASCII uppercasing</a> | ||
the result. | ||
</li> | ||
<li> | ||
<p> | ||
If <var>regionCode</var> is not a valid <a>country | ||
subdivision code element</a> as per [[!ISO3166-2]]'s | ||
section 5.2 "Structure of country subdivision code | ||
elements" (non-normative details below), throw a | ||
<a>RangeError</a> exception. | ||
</p> | ||
<div class="note" title= | ||
"Structure of country subdivision code elements"> | ||
<p> | ||
<strong>Do not implement from this note.</strong> The | ||
structure of a <a>country subdivision code element</a> is | ||
formally defined in [[!ISO3166-2]] (section 5.2). | ||
Although the structure is not expected to change at the | ||
time of writing, implementers are expected to track | ||
updates to [[!ISO3166-2]] directly from ISO. | ||
</p> | ||
<p> | ||
As [[!ISO3166-2]] is not freely available to the general | ||
public, the structure of a <a>country subdivision code | ||
element</a> at the time of publication is as follows: | ||
</p> | ||
<ul> | ||
<li>Two <a>code points</a> that match an [[!ISO3166-1]] | ||
alpha-2 country code. | ||
</li> | ||
<li>A single U+002D (-) <a>code point</a>. | ||
</li> | ||
<li>One, two, or three <a data-cite= | ||
"INFRA#ascii-alphanumeric">ASCII alphanumeric</a> code | ||
points, in any order. | ||
</li> | ||
</ul> | ||
</div> | ||
</li> | ||
<li>Set <var>address</var>.<a>[[\regionCode]]</a> to | ||
<var>regionCode</var>. | ||
</li> | ||
<li>Let <var>region</var> be the corresponding <a>country | ||
subdivision name</a> for <var>regionCode</var>. Where | ||
[[!ISO3166-2]] defines multiple <a>country subdivision | ||
names</a> for a <var>regionCode</var>, it is RECOMMENDED the | ||
user agent select one by matching on: | ||
<ol> | ||
<li>The <a data-cite="!HTML#language">language</a> of | ||
<a data-cite="HTML#the-body-element-2">the body | ||
element</a>. | ||
</li> | ||
<li>The user's preferred languages. | ||
</li> | ||
<li>Any other criteria the user agent deems suitable. | ||
</li> | ||
</ol> | ||
</li> | ||
<li>Set <var>address</var>.<a>[[\region]]</a> to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @domenic, stop reading this! get back to vacation! 🍹 But when you are back... by design, const dict = {
country: "PT",
regionCode: "PT-11",
}
const address = new PaymentAddress(dict);
address.region; // "Lisboa", per ISO ISO3166-2
// And... then..
const dict = {
country: "PT",
regionCode: "PT-11",
region: "Lisbon",
}
const address = new PaymentAddress(dict);
address.region; // Lisbon, per developer override. Hmm.... now I'm wondering if we should allow some members to be nullable on the const dict = {
country: "PT",
regionCode: "PT-11",
region: null, // or undefined, means "derive it for me"
} While: const dict = {
country: "PT",
regionCode: "PT-11",
region: "", // trash it ... I'll handle it
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @domenic, if you are back from vacation, #690 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Whether we want to allow details["region"] to be nullable or not, as some kind of explicit "don't derive this for me, but also make it not a real region value"---I'm not sure. |
||
<var>region</var>. | ||
</li> | ||
</ol> | ||
</li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider deriving region from regionCode, so the caller only has to pass one? I'm thinking ahead to the constructor; do we want to prevent I guess for the cases where there is no corresponding regionCode, we'd still want to pass region. But if regionCode is not the empty string, deriving region from it might be good... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agree. It's definitely doable. ISO3166-2 provides lookup tables, for example:
Where column 2 (defined thing) is "...the country subdivision names in the administrative language of the country concerned, where relevant with diacritic signs..." (as Unicode). Note that "a country’s administrative language is a written language used by the administration of the country at the national level". So, the result won't be in English a lot of the time - but that's fine, IMO. This is not for display purposes. So, something like: The steps to derive a region from a country subdivision code element are as follows. The string takes a DOMString subCode as input and returns a DOMString.
Sound good? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds great! Probably we should get implementer buy-ins though; maybe as a separate PR? Because it'd mean having to ship that table with the browser... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree... ☝️@rsolomakhin, @mnoorenberghe, something to start thinking about. Would appreciate your input. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are already using libaddressinput (and I believe Chromium does too) so it would be great if we could also use that here instead of having two versions of similar data. Does ISO3166-2 only have one name per region? What about when there are multiple official languages? Consider CA-QC: is it "Quebec" or "Québec" in ISO3166-2. libaddressinput provides both but without a clear way to know which one would match ISO3166-2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure how this all fits together but won't this affect what gets returned in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably perform some kind of lookup, based on the document language. But then it gets into preference order for when it doesn't match the user's language (and there is no "en"). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems crazy town, but:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use libaddressinput in Chromium and @sebsg is helping us to add the ISO codes to that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The |
||
<li>If <var>details</var>["<a>languageCode</a>"] is present: | ||
<ol> | ||
<li>If <a data-cite= | ||
|
@@ -2316,6 +2386,17 @@ <h2> | |
internal slot. | ||
</p> | ||
</section> | ||
<section> | ||
<h2> | ||
<dfn>regionCode</dfn> attribute | ||
</h2> | ||
<p data-link-for=""> | ||
Represents the <a>region</a> of the address as an [[!ISO3166-2]] | ||
<a>country subdivision code element</a>. When getting, returns the | ||
value of the <a>PaymentAddress</a>'s <a>[[\regionCode]]</a> | ||
internal slot. | ||
</p> | ||
</section> | ||
<section> | ||
<h2> | ||
<dfn>city</dfn> attribute | ||
|
@@ -2434,9 +2515,20 @@ <h2> | |
<dfn>[[\region]]</dfn> | ||
</td> | ||
<td> | ||
A <a>region</a> as a country subdivision name or the empty | ||
string, such as "Victoria", representing the state of Victoria | ||
in Australia. | ||
A <a>region</a> as a <a>country subdivision name</a> or the | ||
empty string, such as "Victoria", representing the state of | ||
Victoria in Australia. | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<dfn>[[\regionCode]]</dfn> | ||
</td> | ||
<td> | ||
A <a>region</a> represented as a [[!ISO3166-2]] <a>country | ||
subdivision code element</a> stored in its canonical uppercase | ||
form, or the empty string. For example, "<code>PT-11</code>" | ||
represents the Lisbon district of Portugal. | ||
</td> | ||
</tr> | ||
<tr> | ||
|
@@ -2516,6 +2608,7 @@ <h2> | |
DOMString country; | ||
sequence<DOMString> addressLine; | ||
DOMString region; | ||
DOMString regionCode; | ||
DOMString city; | ||
DOMString dependentLocality; | ||
DOMString postalCode; | ||
|
@@ -2550,6 +2643,13 @@ <h2> | |
<dd> | ||
A <a>region</a>. | ||
</dd> | ||
<dt> | ||
<dfn>regionCode</dfn> member | ||
</dt> | ||
<dd> | ||
An <a>region</a>, represented as a <a>country subdivision code | ||
element</a>. | ||
</dd> | ||
<dt> | ||
<dfn>city</dfn> member | ||
</dt> | ||
|
@@ -2684,9 +2784,17 @@ <h2> | |
<var>details</var>["<a>recipient</a>"] to the user-provided recipient | ||
of the transaction, or to the empty string if none was provided. | ||
</li> | ||
<li>If "region" is not in <var>redactList</var>, set | ||
<var>details</var>["<a>region</a>"] to the user-provided region, or | ||
to the empty string if none was provided. | ||
<li>If "region" is not in <var>redactList</var>: | ||
<ol> | ||
<li>Set <var>details</var>["<a>region</a>"] to the user-provided | ||
region, or to the empty string if none was provided. | ||
</li> | ||
<li>If <var>details</var>["<a>region</a>"] has a corresponding | ||
<a>country subdivision code element</a>, set | ||
<var>details</var>["<a>regionCode</a>"] to that <a>country | ||
subdivision code element</a>. | ||
</li> | ||
</ol> | ||
</li> | ||
<li>If "sortingCode" is not in <var>redactList</var>, set | ||
<var>details</var>["<a>sortingCode</a>"] to the user-provided sorting | ||
|
@@ -3923,6 +4031,14 @@ <h2> | |
This specification relies on several other underlying specifications. | ||
</p> | ||
<dl data-sort=""> | ||
<dt> | ||
ISO 3366-2 | ||
</dt> | ||
<dd> | ||
<dfn data-lt="country subdivision names">Country subdivision | ||
name</dfn> and <dfn>country subdivision code element</dfn> are | ||
defined in [[!ISO3166-2]]. | ||
</dd> | ||
<dt> | ||
Infra | ||
</dt> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Adding comment again, so we can discuss here)
@rsolomakhin, I've tried to summarize what you said about how Chrome does the ordering, while keeping the order in which things are matched optional. However, I added matching on the document's body's language as first, to match what we say in
.show()
. The "Any other criteria the user agent deems suitable" if for the fallback you described, whereby you pick the first available.WDYT? Would this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mnoorenberghe, wdty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the specific question is… do you want me to comment on the locale ordering or the spec change in general? For the locale ordering, as long as the UA isn't required to show the PR dialog in a language that the UA doesn't have installed then I'm fine with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a separate note, I wonder whether we really need to derive
region
from theregionCode
… it would be simpler to also return the ISO3166-2 code as theregion
.One concern I have with the spec change is that I've never seen ISO3166-2 used with the country code prefix in the wild. As a web developer I would expect
regionCode
to be "CA" for California, not "US-CA" if I hadn't read documentation on the API and only saw the webidl FWIW. I'm not sure if there are exceptions to cutting off the first 3 characters in order to get the region code specific to the country. If there is then this will likely cause issues for merchants when mapping the PR's address to existing systems.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the information I have at the moment, I'm leaning towards just returning the ISO3166-2 format. It might save us from having to deal with special cases where there is ambiguity, but I also don't know if there are any. I'll try to do a bit more reading.
I don't think there are, from my reading of the ISO3166-2 spec. But I'll take a closer look as it's been a few weeks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming back to this and re-reading the ISO spec, I can't determine that there would be significant issues with chopping off country and dash. I'm still reluctant to do it tho. I'd rather just stick to the full code "just in case" and just so we are not creating new conventions. @mnoorenberghe, is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'm always hesitant to parse other people's strings, ISO 3166-2 is defined to use ISO 3166-1 alpha-2 code elements as the first two characters of the string, followed by the hyphen character, followed by the region itself. So I think we'd be safe in truncated the first three chars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it does also remove a source of ambiguity/redundancy, as
.country
will now need to be there to derive.region
. Do we still attempt to do validation on a synthetic 3166-2 code? I would guess no: we attempt to populateregion
iffcounty
andregionCode
are both there and they both together form a known 3366-2 code. Can work with that.