コード例 #1
0
 result.extend = function (obj) {
   return i18n(i18nExtend(result, {
     get: function (key) {
       return obj[key]
     }
   }));
 }
コード例 #2
0
  init: function(options, globalStorage, appStorage) {
    var lookup = i18nChain(
          options.appDir ? i18nFs(path.resolve(options.appDir, './i18n')) : null
        , i18nFs(path.resolve(__dirname, './i18n'))
      )
      , root = i18n(lookup)
      , choose = chooseLang.bind(null, globalStorage, appStorage, options.defaultLang, options.languages)
      , lang = choose(null)
      , translator = root.lang(lang, true)
      , result = i18n(i18nExtend(translator, {
          get: function (key) {
            if (options[key])
              return options[key]

            // legacy -- start
            if (key === 'title')
              return options.name.toUpperCase()

            if (key === 'appName' || key === 'appname' || key === 'ADVENTURE_NAME')
              return options.name

            if (key === 'rootdir')
              return options.appDir

            if (key === 'COMMAND' || key === 'ADVENTURE_COMMAND')
              return commandify(options.name)
            // legacy -- end

            var exercisePrefix = 'exercise.'
            if (key.indexOf(exercisePrefix) === 0)
              return key.substr(exercisePrefix.length)

            if (key.length > UNDERLINE.length) {
              var end = key.length-UNDERLINE.length
              if (key.indexOf(UNDERLINE) === end)
                return util.repeat('\u2500', chalk.stripColor(result.__(key.substr(0, end))).length + 2)
            }
          }
        }))
      , _exercises = []
    root.fallback = function (key) {
      return '?' + key + '?'
    }
    result.change = function (lng) {
      lang = choose(lng)
      translator.changeLang(lang)
    }
    result.extend = function (obj) {
      return i18n(i18nExtend(result, {
        get: function (key) {
          return obj[key]
        }
      }));
    }
    result.updateExercises = function(exercises) {
      _exercises = exercises;
    }
    result.lang = function () {
      return lang
    }
    return result
  }