Re: [w3c/payment-request] Describe how to implement PaymentAddress.languageCode (#608)

Here's the abstracted algorithm:

1. _Let_ `address` be the given address.
2. _Let_ `addressCountry` be the 2-letter country code of the `address`.
1. _Let_ `countryLanguages` be an unordered of 2-letter language codes for languages known to be used in the `addressCountry`.
1. _Let_ `defaultCountryLanguage` be the primary country language if known, or the first in alphabetical ordering of `countryLanguages` otherwise.
1. _Let_ `countryHasLatinScriptAddressFormat` be a boolean that is true if `addressCountry` has address formatting rules specifically for languages that use Latin script, which is different from the address format for `countryLanguages`.
1. _If_ `countryHasLatinScriptAddressFormat` is true, then _let_ `defaultCountryLatinScriptLanguageTag` be the BCP47 language tag constructed from `defaultCountryLanguage` as the "language subtag" and "Latn" as the "script subtag" in BCP47 terminology.
3. _Let_ `userAgentLocale` be the locale of the user agent.
1. _Let_ `userAgentLanguage` be the language part of the `userAgentLocale`.
1. _Let_ `userAgentScript` be the script part of the `userAgentLocale`, if any.
4. _If_ `countryLanguages` is empty, **return** `userAgentLocale`.
1. _Else if_ `userAgentScript` is "Latn" and `countryHasLatinScriptAddressFormat` is true, **return** `defaultCountryLatinScriptLanguageTag`.
1. _Else if_ `userAgentLanguage` is in the `countryLanguages` set, then **return** the BCP47 language tag constructed from `userAgentLanguage` as the "language subtag" and `addressCountry` as the "region subtag" in BCP47 terminology.
1. _Else if_ `addressCountry` has address formatting rules specifically for languages that use Latin script alphabet and `userAgentLanguage` uses Latin script alphabet, **return** `defaultCountryLatinScriptLanguageTag`.
1. _Else_ **Return** the BCP47 language tag constructed from `defaultCountryLanguage` as the BCP47 "language subtag" and `addressCountry` as the "region subtag" in BCP47 terminology.

(BCP47: https://tools.ietf.org/html/bcp47)

Examples:

```
country="US"
countryLanguages=["en"]
defayltCountryLanguage="en"
countryHasLatinScriptAddressFormat=false
userAgentLocale="en-US"
userAgentLanguage="en"
userAgentScript=undefined
return "en-US"
```

```
country="US"
countryLanguages=["en"]
defayltCountryLanguage="en"
countryHasLatinScriptAddressFormat=false
userAgentLocale="ja-JP"
userAgentLanguage="ja"
userAgentScript=undefined
return "en-US"
```

```
country="JP"
countryLanguages=["ja"]
defaultCountryLanguage="ja"
countryHasLatinScriptAddressFormat=true
userAgentLocale="ja-JP"
userAgentLanguage="ja"
userAgentScript=undefined
return "ja-JP"
```

```
country="JP"
countryLanguages=["ja"]
defaultCountryLanguage="ja"
countryHasLatinScriptAddressFormat=true
userAgentLocale="en-US"
userAgentLanguage="en"
userAgentScript=undefined
return "ja-Latn"
```

```
country="JP"
countryLanguages=["ja"]
defaultCountryLanguage="ja"
countryHasLatinScriptAddressFormat=true
userAgentLocale="ru-Latn"
userAgentLanguage="ru"
userAgentScript="Latn"
return "ja-Latn"
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-request/issues/608#issuecomment-414546200

Received on Tuesday, 21 August 2018 04:28:58 UTC