How to use the i18n.configure function in i18n

To help you get started, we’ve selected a few i18n examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apostrophecms / apostrophe / lib / modules / apostrophe-i18n / index.js View on Github external
construct: function(self, options) {

    var i18nOptions = self.options || {};
    _.defaults(i18nOptions, {
      locales: ['en'],
      cookie: 'apos_language',
      directory: self.apos.rootDir + '/locales'
    });
    i18n.configure(i18nOptions);

    // Make the i18n instance available globally in Apostrophe
    console.log('initial');
    self.apos.i18n = i18n;
  }
};
github eshengsky / HostsDock / main.js View on Github external
function initialize() {
    const shouldQuit = makeSingleInstance();
    if (shouldQuit) {
        return app.exit(0);
    }

    i18n.configure({
        locales: localeArray,
        directory: `${__dirname}/locales`,
        objectNotation: true
    });

    function createWindow() {
        const windowOptions = {
            width: 1080,
            minWidth: 680,
            height: 840,
            icon: path.join(__dirname, `${process.platform === 'win32' ? '/public/image/hostsdock.ico' : '/public/image/hostsdock.png'}`),
            show: false
        };

        // Create the browser window.
        mainWindow = new BrowserWindow(windowOptions);
github stevenvergenz / dfrpg-toonstore / src / i18n.js View on Github external
express = require('express');

var global = require('./global.js');

// the translation middleware
var config = {
	locales: ['en-US','pt-BR','cs-CZ','fr-CA'],
	defaultLocale: 'en-US',
	directory: libpath.resolve(__dirname,'..','locales'),
	extension: '.json',
	updateFiles: false,
	objectNotation: true,
	cookie: 'preferredLang'
};

i18n.configure(config);

exports.detect = function(req,res,next)
{
	res.i18n = new MyI18n();
	res.redirect = function(url)
	{
		if( this.i18n.pathLocale ){
			return express.response.redirect.call(this, '/'+this.i18n.pathLocale+url);
		}
		else {
			return express.response.redirect.call(this, url);
		}
	}.bind(res);

	var pathLang = detectPathLocale(req.url, req);
	var cookieLang = detectCookieLocale(req.cookies[config.cookie]);
github alphagov / pay-frontend / app / models / card.js View on Github external
'use strict'

// NPM dependencies
const _ = require('lodash')
const changeCase = require('change-case')
const AWSXRay = require('aws-xray-sdk')
const { getNamespace } = require('continuation-local-storage')
const i18n = require('i18n')

// Local dependencies
const logger = require('../utils/logger')(__filename)
const cardIdClient = require('../services/clients/cardid_client')
const { NAMESPACE_NAME, XRAY_SEGMENT_KEY_NAME } = require('../../config/cls')
const i18nConfig = require('../../config/i18n')

i18n.configure(i18nConfig)

const checkCard = function (cardNo, allowed, language, correlationId, subSegment) {
  return new Promise(function (resolve, reject) {
    const startTime = new Date()
    const data = { cardNumber: parseInt(cardNo) }

    i18n.setLocale(language || 'en')

    // Use a subSegment if passed, otherwise get our main segment
    if (!subSegment) {
      const namespace = getNamespace(NAMESPACE_NAME)
      subSegment = namespace.get(XRAY_SEGMENT_KEY_NAME)
    }

    AWSXRay.captureAsyncFunc('cardIdClient_post', function (postSubsegment) {
      if (cardNo.length > 0 && cardNo.length < 11) {
github gpmer / gpm.js / app / prepare.ts View on Github external
const currentLocale = globalConfig.get('locale') || defaults.locale;

  const i18nConfig: I18nConfig$ = {
    locales: ['en_US', 'zh_CN'],
    defaultLocale:
      supports.findIndex(v => v === currentLocale) >= 0
        ? currentLocale
        : defaults.locale,
    directory: paths.project + '/locales',
    extension: '.json',
    register: global,
    objectNotation: true
  };

  i18n.configure(i18nConfig);
}
github alphagov / pay-frontend / server.js View on Github external
function initialisei18n (app) {
  i18n.configure(i18nConfig)
  app.use(i18n.init)
  app.use(i18nPayTranslation)
}
github stefanvanherwijnen / quasar-auth-starter / backend / src / common / server.ts View on Github external
import bodyParser from 'body-parser'
import Express from 'express'
import * as http from 'http'
import Knex from 'knex'
import { Model } from 'objection'
import * as os from 'os'
import * as path from 'path'
import knexConfig from '../../knexfile'
import l from './logger'
import swagger from './swagger'
import morgan from 'morgan'
import cors from 'cors'

import i18n from 'i18n'
i18n.configure({
  locales: ['en', 'nl'],
  defaultLocale: 'nl',
  register: global,
  objectNotation: true,
  syncFiles: true,
  directory: __dirname + '/../i18n',
})

const env = process.env.NODE_ENV || process.env.APP_ENV
const knex = Knex(knexConfig[env])
Model.knex(knex)

const app = Express()

export default class ExpressServer {
  public constructor() {
github robsonrosilva / advpl-sintaxe / out / src / merge.js View on Github external
function localize(key) {
    const vscodeOptions = JSON.parse(process.env.VSCODE_NLS_CONFIG).locale.toLowerCase();
    let i18n = require('i18n');
    let locales = ['en', 'pt-br'];
    i18n.configure({
        locales: locales,
        directory: __dirname + '\\locales'
    });
    i18n.setLocale(locales.indexOf(vscodeOptions) + 1 ? vscodeOptions : 'en');
    return i18n.__(key);
}
github robsonrosilva / advpl-sintaxe / src / merge.ts View on Github external
function localize(key: string) {
    const vscodeOptions = JSON.parse(
        process.env.VSCODE_NLS_CONFIG
    ).locale.toLowerCase();
    let i18n = require('i18n');
    let locales = ['en', 'pt-br'];
    i18n.configure({
        locales: locales,
        directory: __dirname + '\\locales'
    });
    i18n.setLocale(locales.indexOf(vscodeOptions) + 1 ? vscodeOptions : 'en');
    return i18n.__(key);
}