1

Intl.Displaynames()コンストラクターは、Javascript での言語、地域、およびスクリプトの表示名の翻訳を可能にします。

残念ながら、これは Safari バージョンではサポートされていません < 14.1.( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames#browser_compatibilityを参照)。

古いバージョンの Safari でこれを機能させるにはどうすればよいですか?

4

1 に答える 1

1

ポリフィル ( 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')
于 2021-09-28T07:55:35.337 に答える