How to use the i18n.init 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 balderdashy / sails / lib / hooks / views / render.js View on Github external
'views': sails.config.paths.views
      }
    });

    // Set up a mock request for i18n to use as context
    var req = {
      headers: {}
    };

    // Initialize i18n if hook is enabled
    if (sails.hooks.i18n) {

      // If a locale was specified as an option, render the view with that locale
      req.headers['accept-language'] = options.locale || sails.hooks.i18n.defaultLocale;

      require('i18n').init(req, options, function() {

        // Set the locale if necessary
        if (options.locale) {
          req.locale = options.locale;
        }

        // Render the view
        sails.config.views.engine.fn(absPathToView, options, cb_view);
      });
    } else {
      sails.config.views.engine.fn(absPathToView, options, cb_view);
    }

  };
};
github Terminal / discordapps.dev / src / discord / handler.js View on Github external
module.exports = async (message, callback) => {
  const mss = {};

  // Set default values
  mss.content = message.content.trim() || '';
  mss.prefix = prefixes.find(prefix => mss.content.toLowerCase().startsWith(prefix)) || '';
  mss.command = '';
  mss.input = '';
  mss.admin = 0;

  i18n.init(message);

  // If there's a prefix, get rid of the prefix and check for any command
  if (mss.prefix && !message.author.bot) {
    const noprefix = mss.content.substring(mss.prefix.length).trim();
    mss.command = Object.keys(commands).find(command => noprefix.startsWith(command)) || '';
    if (mss.command) {
      mss.input = noprefix.substring(mss.command.length).trim();
      mss.cleanInput = clean(message, mss.input);
    }
  }

  // Set the permission level
  /*
   * 3: Administrator of the bot
   * 2: Has administrator role
   * 1: Can kick/ban
github ladjs / lad / template / helpers / i18n.js View on Github external
i18n.middleware = function(ctx, next) {
  // expose api methods to `ctx.req` and `ctx.state`
  i18n.init(ctx.req, ctx.state);

  // override the existing locale detection with our own
  // in order of priority:
  //
  // 1. check the URL, if `/de` then locale is `de`
  // 2. check the cookie
  // 3. check Accept-Language last

  let locale = config.defaultLocale;

  if (_.includes(config.locales, ctx.url.split('/')[1]))
    locale = ctx.url.split('/')[1];
  else if (
    ctx.cookies.get('locale') &&
    _.includes(config.locales, ctx.cookies.get('locale'))
  )
github 7coil / discordmailhooks / discord / handler.js View on Github external
module.exports = async (message) => {
  const mss = {};

  // Set default values
  mss.content = message.content.trim() || '';
  mss.prefix = prefixes.find(prefix => mss.content.toLowerCase().startsWith(prefix)) || '';
  mss.command = '';
  mss.input = '';
  mss.admin = 0;

  i18n.init(message);

  // If there's a prefix, get rid of the prefix and check for any command
  if (mss.prefix && !message.author.bot) {
    const noprefix = mss.content.substring(mss.prefix.length).trim();
    mss.command = Object.keys(commands).find(command => noprefix.startsWith(command)) || '';
    if (mss.command) {
      mss.input = noprefix.substring(mss.command.length).trim();
      mss.cleanInput = clean(message, mss.input);
    }
  }

  if (config.discord.admins.includes(message.author.id)) {
    mss.admin = 3;
  } else if (message.member && message.member.permission.has('administrator')) {
    mss.admin = 2;
  } else if (message.member && message.member.permission.has('manageWebhooks')) {
github SmartThingsCommunity / smartapp-sdk-nodejs / lib / util / smart-app-context.js View on Github external
// For constructing context for proactive API calls not in response to a lifecycle event
			default:
				authToken = data.authToken
				refreshToken = data.refreshToken
				this.executionId = ''
				this.installedAppId = data.installedAppId
				this.locationId = data.locationId
				this.config = data.config
				this.locale = data.locale
				break
		}

		if (app._localizationEnabled) {
			if (this.locale) {
				this.headers = {'accept-language': this.locale}
				i18n.init(this)
			}
		}

		if (authToken) {
			this.api = new SmartThingsApi({
				authToken,
				refreshToken,
				clientId: app._clientId,
				clientSecret: app._clientSecret,
				log: app._log,
				apiUrl: app._apiUrl,
				refreshUrl: app._refreshUrl,
				locationId: this.locationId,
				installedAppId: this.installedAppId,
				contextStore: app._contextStore,
				apiMutex
github 7coil / discordmail / server / discord / handler.js View on Github external
// Set default values
	mss.content = message.content.trim() || '';
	mss.prefix = prefixes.find(prefix => mss.content.toLowerCase().startsWith(prefix)) || '';
	mss.context = null;
	mss.command = '';
	mss.input = '';
	mss.cleanInput = '';
	mss.clean = clean;
	mss.admin = 0;
	mss.banned = null;
	mss.inbox = '0';
	mss.dmail = null;
	mss.ratelimit = 0;

	i18n.init(message);

	// If there's a prefix, get rid of the prefix and check for any command
	if (mss.prefix && !message.author.bot) {
		mss.context = usrPrefix.includes(mss.prefix) ? 'user' : 'guild';
		mss.inbox = mss.context === 'user' ? message.author.id : message.channel.id;
		const noprefix = mss.content.substring(mss.prefix.length).trim();
		mss.command = Object.keys(commands).find(command => noprefix.startsWith(command)) || '';
		if (mss.command) {
			mss.input = noprefix.substring(mss.command.length).trim();
			mss.cleanInput = clean(message, mss.input);

			if (config.get('discord').admins.includes(message.author.id)) {
				mss.admin = 3;
			} else if (message.member && message.member.permission.has('administrator')) {
				mss.admin = 2;
			} else if (message.member && (message.member.permission.has('kickMembers') || message.member.permission.has('banMembers'))) {
github 7coil / discordmail / server / discord / utils / init / index.js View on Github external
const init = (message, pre, clean, next) => {
	message.prefix = pre[1];
	message.command = pre[2];
	message.input = pre[3] || null;
	message.words = (pre[3] || '').split(' ');
	message.name = utils.dmail.name(message.author.username);
	message.context = config.get('discord').prefix.user.includes(message.prefix.toLowerCase()) ? 'user' : 'guild';
	message.inbox = message.context === 'user' ? message.author.id : (message.channel.guild && message.channel.guild.id) || 'Not inside a guild';
	message.clean = {
		prefix: clean[1],
		command: clean[2],
		input: clean[3],
		words: (pre[3] || '').split(' ')
	};
	i18n.init(message);
	r.table('i18n')
		.get(message.inbox)
		.run(r.conn, (err1, res1) => {
			if (err1) {
				console.dir(err1);
			} else if (res1 && res1.lang) {
				message.setLocale(res1.lang);
			}
			r.table('ratelimit')
				.get(message.author.id)
				.run(r.conn, (err2, res2) => {
					if (err2) {
						message.channel.createMessage(message.__('err_generic'));
					} else if (res2 && (res2.timeout - Date.now()) > 0) {
						message.channel.createMessage(message.__('err_ratelimit', { time: (res2.timeout - Date.now()) / 1000 }));
					} else {
github baryon / node.blog / app.js View on Github external
app.use(function (req, res, next) {
        var lang = req.session.lang;
        if(lang){
        	i18n.setLocale(req, lang);
        	next();
        }else
        	i18n.init(req, res, next);
    });
github basemkhirat / express-mvc / libs / i18n.js View on Github external
module.exports = function (req, res, next) {

    i18n.init(req, res);

    global._lang = res.__;

    return next();
};
github stefanvanherwijnen / quasar-auth-starter / backend / src / common / server.ts View on Github external
public constructor() {
    const root = path.normalize(`${__dirname}/../..`)
    app.set('appPath', `${root}client`)
    app.use(bodyParser.json({ limit: process.env.REQUEST_LIMIT || '100kb' }))
    app.use(bodyParser.urlencoded({ extended: true, limit: process.env.REQUEST_LIMIT || '100kb' }))
    app.use(Express.static(`${root}/public`))
    app.use(i18n.init)
    app.use(cors())
  }