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.DisplayNames script does not work #2622

Closed
mhf-ir opened this issue Feb 20, 2021 · 7 comments · May be fixed by nuel/mastodon-old#660 or navikt/engangsstonad#717
Closed

Intl.DisplayNames script does not work #2622

mhf-ir opened this issue Feb 20, 2021 · 7 comments · May be fixed by nuel/mastodon-old#660 or navikt/engangsstonad#717

Comments

@mhf-ir
Copy link

mhf-ir commented Feb 20, 2021

How can i use as CDN package?
Older browser seems not support to esm module so we need add

var testIntl = function() {
  return (
      typeof Intl !== 'undefined' &&
      typeof Intl.Collator !== 'undefined' &&
      typeof Intl.DateTimeFormat !== 'undefined' &&
      typeof Intl.DateTimeFormat.prototype.formatToParts !== 'undefined' &&
      typeof Intl.DateTimeFormat.prototype.resolvedOptions !== 'undefined' &&
      typeof Intl.NumberFormat !== 'undefined' &&
      typeof Intl.PluralRules !== 'undefined' &&
      typeof Intl.DisplayNames !== 'undefined' &&
      typeof Intl.ListFormat !== 'undefined' &&
      typeof Intl.Locale !== 'undefined' &&
      typeof Intl.getCanonicalLocales !== 'undefined' &&
      typeof Intl.RelativeTimeFormat !== 'undefined' &&
      new Intl.DisplayNames('en-US', { type: 'region' }).of('IR') === 'Iran' &&
      new Intl.DisplayNames('fa-IR', { type: 'language' }).of('fa') ===
        'فارسی' &&
      new Intl.DisplayNames('de-DE', { type: 'script' }).of('arab') ===
        'Arabisch' &&
      new Intl.DisplayNames('ar-EG', { type: 'currency' }).of('USD') ===
        'دولار أمريكي'
  );
}
if (testIntl() === false) {
   document.write('<script src="https://polyfill.io/v3/polyfill.min.js?features=Intl"></script>');
   // lets try add formatjs
   document.write('<script src="??????????????"></script>');
}
@longlho
Copy link
Member

longlho commented Feb 21, 2021

@mhf-ir
Copy link
Author

mhf-ir commented Feb 21, 2021

i think it's better to be part of documentation.
I can't see what's the URL parameters and possible values

@mhf-ir
Copy link
Author

mhf-ir commented Feb 21, 2021

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=Intl.DisplayNames%2CIntl.DisplayNames.~locale.en%2CIntl.RelativeTimeFormat%2CIntl.ListFormat%2CIntl.NumberFormat%2CIntl.RelativeTimeFormat.~locale.en%2CIntl.ListFormat.~locale.en%2CIntl.NumberFormat.~locale.en"></script>
</head>
<body>
  <script>
    console.log(new Intl.DisplayNames('en-US', { type: 'region' }).of('IR')) // OK
    console.log(new Intl.DisplayNames('en-US', { type: 'language' }).of('fa')) // OK
    console.log(new Intl.DisplayNames('en-US', { type: 'currency' }).of('IRR')) // OK
    
    console.log(new Intl.DisplayNames('en-US', { type: 'script' }).of('arab')) // WRONG `arab`  must be "Arabic"
  </script>
</body>
</html>

https://jsbin.com/fitosabuba/edit?html,console,output
Demo seems script not applied. Test validate value with latest nightly firefox.

@longlho
Copy link
Member

longlho commented Feb 21, 2021

new Intl.DisplayNames('en-US', { type: 'script' }).of('arab')) returns arab in Chrome as well

@mhf-ir
Copy link
Author

mhf-ir commented Feb 21, 2021

It's bug, follow ICU/Intl not chrome.

https://bugs.chromium.org/p/chromium/issues/detail?id=1176979

ICU/Intl could be cross check using different implementation, easy and most mature implementation is PHP version.

<?php

echo locale_get_display_script('ar-Arab-EG', 'en'); // Arabic

PHP using libicu since version 5 and it's mature enough to be good point for check.

@longlho
Copy link
Member

longlho commented Feb 21, 2021

hmm most non-web envs use libicu (Chrome, Rust, Python...) let me see

@longlho longlho changed the title jsdelivr.com or etc CDN ? Intl.DisplayNames script does not work Feb 22, 2021
@longlho
Copy link
Member

longlho commented Feb 22, 2021

Latest version should have this fix.
Upstream PR at polyfill-library: JakeChampion/polyfill-library#998

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment