function initTest() { const i18nextOptions = {}; i18next .use(sprintfA) .use(sprintfB) .init(i18nextOptions); i18next .init({ overloadTranslationOptionHandler: sprintfA.overloadTranslationOptionHandler }); i18next .init({ overloadTranslationOptionHandler: sprintfB.overloadTranslationOptionHandler }); }
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); }
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 }
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(); } } ); });
function requestObjectTest() { var i18nextOptions = {}; i18next .use(middleware.LanguageDetector) .init(i18nextOptions); var app = express(); app.use(middleware.handle(i18next, { ignoreRoutes: ["/foo"], removeLngFromUrl: false })); }
// 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); }); }
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;
// 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);
/* 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,
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;