瀏覽代碼

Use Intl.DisplayNames, closes #2790

Renée Kooi 4 年之前
父節點
當前提交
762f29cc8d
共有 3 個文件被更改,包括 13 次插入16 次删除
  1. 5 0
      package-lock.json
  2. 8 15
      website/inject.js
  3. 0 1
      website/package.json

+ 5 - 0
package-lock.json

@@ -8116,6 +8116,8 @@
           "integrity": "sha512-cRQ5Qw87SNS4b2v+UfjUW5uAVx4nv6pj9I0cu6ys8x+t7NjVo3cOjaT4Bns1/xxy6xzWv/4WT0LbG5h+NNGNMA==",
           "requires": {
             "@types/tus-js-client": "^1.8.0",
+            "@uppy/companion-client": "^1.5.0",
+            "@uppy/utils": "^3.1.0",
             "tus-js-client": "^1.8.0"
           }
         },
@@ -8190,7 +8192,10 @@
     "@uppy-example/svelte-example": {
       "version": "file:examples/svelte-example",
       "requires": {
+        "@uppy/core": "^1.14.1",
         "@uppy/svelte": "file:packages/@uppy/svelte",
+        "@uppy/webcam": "^1.8.1",
+        "@uppy/xhr-upload": "^1.6.7",
         "sirv-cli": "^1.0.0"
       }
     },

+ 8 - 15
website/inject.js

@@ -9,7 +9,6 @@ const prettierBytes = require('@transloadit/prettier-bytes')
 const browserify = require('browserify')
 const touch = require('touch')
 const glob = require('glob')
-const LocaleCode = require('locale-code')
 
 const webRoot = __dirname
 const uppyRoot = path.join(__dirname, '../packages/uppy')
@@ -19,6 +18,9 @@ const localesRoot = path.join(__dirname, '../packages/@uppy/locales')
 const configPath = path.join(webRoot, '/themes/uppy/_config.yml')
 const { version } = require(path.join(uppyRoot, '/package.json'))
 
+const regionalDisplayNames = new Intl.DisplayNames('en-US', { type: 'region' })
+const languageDisplayNames = new Intl.DisplayNames('en-US', { type: 'language' })
+
 const defaultConfig = {
   comment: 'Auto updated by inject.js',
   uppy_version_anchor: '001',
@@ -208,26 +210,17 @@ function injectLocaleList () {
     // we renamed the es_GL → gl_ES locale, and kept the old name
     // for backwards-compat, see https://github.com/transloadit/uppy/pull/1929
     if (localeName === 'es_GL') return
-    let localeNameWithDash = localeName.replace(/_/g, '-')
-
-    const parts = localeNameWithDash.split('-')
-    let variant = ''
-    if (parts.length > 2) {
-      const lang = parts.shift()
-      const country = parts.shift()
-      variant = parts.join(', ')
-      localeNameWithDash = `${lang}-${country}`
-    }
+    const [languageCode, regionCode, variant] = localeName.split(/[-_]/)
 
-    const languageName = LocaleCode.getLanguageName(localeNameWithDash)
-    const countryName = LocaleCode.getCountryName(localeNameWithDash)
+    const languageName = languageDisplayNames.of(languageCode)
+    const regionName = regionalDisplayNames.of(regionCode)
     const npmPath = `<code class="raw"><a href="https://www.npmjs.com/package/@uppy/locales">@uppy/locales</a>/lib/${localeName}</code>`
     const cdnPath = `[\`${localeName}.min.js\`](https://releases.transloadit.com/uppy/locales/v${localePackageVersion}/${localeName}.min.js)`
     const githubSource = `[\`${localeName}.js\`](https://github.com/transloadit/uppy/blob/master/packages/%40uppy/locales/src/${localeName}.js)`
-    const mdTableRow = `| ${languageName}<br/> <small>${countryName}</small>${variant ? `<br /><small>(${variant})</small>` : ''} | ${npmPath} | ${cdnPath} | ✏️ ${githubSource} |`
+    const mdTableRow = `| ${languageName}<br/> <small>${regionName}</small>${variant ? `<br /><small>(${variant})</small>` : ''} | ${npmPath} | ${cdnPath} | ✏️ ${githubSource} |`
     mdRows.push(mdTableRow)
 
-    localeList[localeName] = `${languageName} (${countryName}${variant ? ` ${variant}` : ''})`
+    localeList[localeName] = `${languageName} (${regionName}${variant ? `, ${variant}` : ''})`
   })
 
   const resultingMdTable = mdTable.concat(mdRows.sort()).join('\n').replace('%count%', mdRows.length)

+ 0 - 1
website/package.json

@@ -33,7 +33,6 @@
     "hexo-server": "^1.0.0",
     "hexo-util": "^1.9.1",
     "js-yaml": "^3.13.1",
-    "locale-code": "^2.0.2",
     "marked": "^0.7.0",
     "mdast-util-inject": "1.1.0",
     "mkdirp": "0.5.1",