ポリフィル ( https://formatjs.io/docs/polyfills/intl-displaynames/を参照) を使用して、古い Safari バージョンでこれを機能させることができます。
次のポリフィルをコードに追加して、Intl.DisplayNames()
コンストラクターが期待どおりに機能するようにします。
// the actual polyfills:
require('@formatjs/intl-locale/polyfill');
require('@formatjs/intl-displaynames/polyfill');
// the locale data of the languages that you need to support:
require('@formatjs/intl-displaynames/locale-data/de');
require('@formatjs/intl-displaynames/locale-data/en');
これには、次の依存関係が必要です。
"@formatjs/intl-displaynames"
"@formatjs/intl-getcanonicallocales"
"@formatjs/intl-locale"
その後、コンストラクターはポリフィルされ、使用できるようになります。例えば:
const translatedRegionNames = new Intl.DisplayNames(['en'], {type: 'region'});
...
const translatedCountryName = translatedRegionNames.of('US')