当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript i18next.use函数代码示例

本文整理汇总了TypeScript中i18next.use函数的典型用法代码示例。如果您正苦于以下问题:TypeScript use函数的具体用法?TypeScript use怎么用?TypeScript use使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了use函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: detectorOptionsTest

function detectorOptionsTest() {
    var options = {
        // order and from where user language should be detected
        order: [/*'path', 'session', */ 'querystring', 'cookie', 'header'],

        // keys or params to lookup language from
        lookupQuerystring: 'lng',
        lookupCookie: 'i18next',
        lookupSession: 'lng',
        lookupFromPathIndex: 0,

        // cache user language
        caches: false, // ['cookie']

        // optional expire and domain for set cookie
        cookieExpirationDate: new Date(),
        cookieDomain: 'myDomain'
    };

    i18next
        .use(middleware.LanguageDetector)
        .init({
            detection: options
        });

    var lngDetector = new middleware.LanguageDetector(null, options);
    lngDetector.init(options);
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:28,代码来源:i18next-express-middleware-tests.ts

示例2: enableFor

  static enableFor (app: express.Express) {
    i18next
      .use(Backend)
      .use(postProcessor)
      .use(middleware.LanguageDetector)
      .init({
        backend: {
          loadPath: path.join(__dirname, '../../locales/{{lng}}/{{ns}}.po')
        },
        detection: {
          order: ['querystring', 'cookie'],
          lookupQuerystring: 'lang',
          lookupCookie: 'lang',
          caches: ['cookie']
        },
        interpolation: {
          escapeValue: false // Escaping is already handled by Nunjucks
        },
        whitelist: ['en', 'cy'],
        fallbackLng: 'en',
        nsSeparator: false,
        keySeparator: false
      })

    app.use(middleware.handle(i18next))
    return i18next
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:27,代码来源:index.ts

示例3: Promise

 return new Promise((resolve, reject) => {
   // See https://github.com/i18next/ng-i18next
   i18use(XHR);
   i18init(
     {
       initImmediate: true,
       debug: $DIM_FLAVOR === 'dev',
       lng: defaultLanguage(),
       fallbackLng: 'en',
       lowerCaseLng: true,
       load: 'currentOnly',
       interpolation: {
         escapeValue: false,
         format(val, format) {
           if (format === 'pct') {
             return percent(parseFloat(val));
           } else if (format === 'humanBytes') {
             return humanBytes(parseInt(val, 10));
           }
           return val;
         }
       },
       backend: {
         loadPath(lng) {
           const path = {
             en,
             it,
             de,
             fr,
             es,
             'es-mx': esMX,
             ja,
             'pt-br': ptBR,
             pl,
             ru,
             ko,
             'zh-cht': zhCHT,
             'zh-chs': zhCHS
           }[lng];
           if (!path) {
             throw new Error(`unsupported language ${lng}`);
           }
           return path;
         }
       },
       returnObjects: true
     },
     (error) => {
       if (error) {
         reject(error);
       } else {
         resolve();
       }
     }
   );
 });
开发者ID:w1cked,项目名称:DIM,代码行数:56,代码来源:i18n.ts

示例4:

import * as i18next from 'i18next';
import * as XHR from 'i18next-xhr-backend';

const i18n = i18next
  .use(XHR)
  .init({
    fallbackLng: 'ja',
    ns: ['scenario'],
    defaultNS: 'scenario',
    interpolation: {
      escapeValue: false, // not needed for react!!
    },

    backend: {
      loadPath: '/lang/{{lng}}/{{ns}}.json',
    },
    react: {
      wait: true,
    },
  });

export default i18n;
开发者ID:kanecop,项目名称:react_laravel,代码行数:22,代码来源:i18n.ts

示例5: initTest

function initTest() {
    const i18nextOptions = {};
    i18next
      .use(sprintfA)
      .use(sprintfB)
      .init(i18nextOptions);
      i18next
        .init({ overloadTranslationOptionHandler: sprintfA.overloadTranslationOptionHandler });
      i18next
        .init({ overloadTranslationOptionHandler: sprintfB.overloadTranslationOptionHandler });
}
开发者ID:0815fox,项目名称:DefinitelyTyped,代码行数:11,代码来源:i18next-sprintf-postprocessor-tests.ts

示例6: requestObjectTest

function requestObjectTest() {
    var i18nextOptions = {};
    i18next
        .use(middleware.LanguageDetector)
        .init(i18nextOptions);

    var app = express();
    app.use(middleware.handle(i18next, {
        ignoreRoutes: ["/foo"],
        removeLngFromUrl: false
    }));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:12,代码来源:i18next-express-middleware-tests.ts

示例7: initApp

// Initialize the application
function initApp() {
  // Initialize the internationalization
  I18n.use(I18nXhrBackend)
    .use(I18nLanguageDetector)
    .init({
        ns: ['admiral', 'kubernetes', 'base'],
        defaultNS: 'admiral',
        fallbackLng: 'en',
        backend: {
            loadPath: 'assets/i18n/{{ns}}.{{lng}}.json'
        }
    }, () => {
      // Load configuration
      var xhr = new XMLHttpRequest();

      xhr.onreadystatechange = function () {
        if (xhr.readyState == XMLHttpRequest.DONE) {
          let properties = JSON.parse(xhr.responseText).documents;

          var configurationProperties = {};
          for (var prop in properties) {
            if (properties.hasOwnProperty(prop)) {

              configurationProperties[properties[prop].key] = properties[prop].value;
            }
          }

          Utils.initializeConfigurationProperties(configurationProperties);
          platformBrowserDynamic().bootstrapModule(AppModule);
        }
      };

      let configPropsUrl = Links.CONFIG_PROPS;
      if (window['getBaseServiceUrl']) {
        configPropsUrl = window['getBaseServiceUrl'](configPropsUrl);
      }

      xhr.open('GET', configPropsUrl + '?expand=true&documentType=true', true);
      xhr.setRequestHeader('Accept', 'application/json');
      xhr.send(null);
  });
}
开发者ID:mdharamadas1,项目名称:admiral,代码行数:43,代码来源:main.ts

示例8: lookup

    // cache user language on
    caches: ['localStorage', 'cookie'],

    // optional expire and domain for set cookie
    cookieMinutes: 10,
    cookieDomain: 'myDomain'
};
var myDetector = {
    name: 'myDetectorsName',

    lookup(options: Object) {
        // options -> are passed in options
        return 'en';
    },

    cacheUserLanguage(lng: string, options: Object) {
        // options -> are passed in options
        // lng -> current language, will be called after init and on changeLanguage

        // store it
    }
};

i18next.use(LngDetector).init({
    detection: options
});

const lngDetector = new LngDetector(null, options);
lngDetector.init(options);
lngDetector.addDetector(myDetector);
开发者ID:DanCorder,项目名称:DefinitelyTyped,代码行数:30,代码来源:i18next-browser-languagedetector-tests.ts

示例9: describe

/* Allow chai assertions which don't end in a function call, e.g. expect(thing).to.be.undefined */
/* tslint:disable:no-unused-expression */

import * as i18next from 'i18next'
import * as postProcessor from 'i18next-sprintf-postprocessor'
i18next.use(postProcessor).init()

import { expect } from 'chai'
import * as moment from 'moment'
import { Validator } from '@hmcts/class-validator'

import { expectValidationError } from 'test/app/forms/models/validationUtils'

import { DatePaid } from 'paid-in-full/form/models/datePaid'
import { ValidationErrors } from 'forms/validation/validationErrors'
import { LocalDate, ValidationErrors as LocalDateValidationErrors } from 'forms/models/localDate'

describe('DatePaid', () => {
  describe('form object deserialization', () => {
    it('should return undefined when value is undefined', () => {
      expect(DatePaid.fromObject(undefined)).to.be.undefined
    })

    it('should return null when value is null', () => {
      expect(DatePaid.fromObject(null)).to.be.equal(null)
    })

    it('should deserialize all fields', () => {
      expect(DatePaid.fromObject({
        date: {
          year: 2017,
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:datePaid.ts

示例10:

import * as i18n from "i18next";
import * as LanguageDetector from "i18next-browser-languagedetector";
import * as XHR from "i18next-xhr-backend";

i18n.use(XHR);
i18n.use(LanguageDetector);
i18n.init({
  defaultNS: "dashboard",
  fallbackLng: "en",
  interpolation: {
    escapeValue: false
  },
  keySeparator: false,
  ns: ["dashboard"],
  nsSeparator: false
});

export default i18n;
开发者ID:elwoodxblues,项目名称:saleor,代码行数:18,代码来源:i18n.ts


注:本文中的i18next.use函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。