Просмотр исходного кода

impl migrateDeprecatedLocaleId

Yuki Takei 5 лет назад
Родитель
Сommit
79f7f109ab
1 измененных файлов с 25 добавлено и 2 удалено
  1. 25 2
      src/lib/util/locale-utils.js

+ 25 - 2
src/lib/util/locale-utils.js

@@ -2,6 +2,12 @@ const fs = require('fs');
 
 const helpers = require('./helpers');
 
+const DEPRECATED_LOCALE_IDS = ['en', 'ja'];
+const MIGRATE_LOCALE_MAP = {
+  en: 'en_US',
+  ja: 'ja_JP',
+};
+
 /**
  * List locales dirents
  */
@@ -23,12 +29,29 @@ function listLocaleMetadatas() {
 /**
  * List locales IDs (=subdir names)
  */
-function listLocaleIds() {
-  return listLocaleMetadatas()
+function listLocaleIds(includeDeprecatedIds = false) {
+  let list = listLocaleMetadatas()
     .map(meta => meta.id);
+
+  if (includeDeprecatedIds) {
+    list = list.concat(DEPRECATED_LOCALE_IDS);
+  }
+
+  return list;
+}
+
+function migrateDeprecatedLocaleId(localeId) {
+  const toValue = MIGRATE_LOCALE_MAP[localeId];
+
+  if (toValue != null) {
+    return toValue;
+  }
+
+  return localeId;
 }
 
 module.exports = {
   listLocaleMetadatas,
   listLocaleIds,
+  migrateDeprecatedLocaleId,
 };