阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js 检测国际化支持

      Node.js 检测国际化支持

      To verify that ICU is enabled at all (system-icu, small-icu, or full-icu), simply checking the existence of Intl should suffice:

      const hasICU = typeof Intl === 'object';
      

      Alternatively, checking for process.versions.icu, a property defined only when ICU is enabled, works too:

      const hasICU = typeof process.versions.icu === 'string';
      

      To check for support for a non-English locale (i.e. full-icu or system-icu), Intl.DateTimeFormat can be a good distinguishing factor:

      const hasFullICU = (() => {
        try {
          const january = new Date(9e8);
          const spanish = new Intl.DateTimeFormat('es', { month: 'long' });
          return spanish.format(january) === 'enero';
        } catch (err) {
          return false;
        }
      })();
      

      For more verbose tests for Intl support, the following resources may be found to be helpful:

      • btest402: Generally used to check whether Node.js with Intl support is built correctly.
      • Test262: ECMAScript’s official conformance test suite includes a section dedicated to ECMA-402.

      更多内容请参考:Node.js 国际化支持,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录