How to use the i18n.setLocale 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 thorpelawrence / alexa-spotify-connect / connect.js View on Github external
app.pre = function (req, res, _type) {
    i18n.configure({
        directory: __dirname + '/locales',
        defaultLocale: 'en-GB',
        register: req
    });
    if (req.data.request.locale) {
        i18n.setLocale(req.data.request.locale);
    }
    // Error if the application ID of the request is not for this skill
    if (req.applicationId != applicationId &&
        req.getSession().details.application.applicationId != applicationId) {
        throw "Invalid applicationId";
    }
    // Check that the user has an access token, if they have linked their account
    if (!(req.context.System.user.accessToken || req.getSession().details.user.accessToken)) {
        res.say(req.__("You have not linked your Spotify account, check your Alexa app to link the account"));
        res.linkAccount();
    }
};
github zhangyuanwei / node-siri / siri.js View on Github external
//   2. Environment variables
//   3. The file 'config.json'
nconf.argv()
     .env()
     .file({
        file: './config.json'
     });

i18n.configure({
    locales: ['en', 'zh', 'de', 'es', 'fr', 'it', 'ja', 'ru'],
    defaultLocale: 'en',
    updateFiles: false,
    extension: '.js',
    directory: __dirname + '/locales'
});
i18n.setLocale(nconf.get('locale'));

var SIRI_SERVER = nconf.get('server') || 'guzzoni.apple.com',
    SIRI_PORT = nconf.get('port') || 443,
    DUMP_DATA = (nconf.get('dumpdata') === null) ? false : nconf.get('dumpdata'),
    DNS_PROXY = (nconf.get('dnsproxy') === null) ? true : nconf.get('dnsproxy');

function __(str) {
    return i18n.__(str);
}

function toArray(list) {
    return [].slice.call(list, 0);
}

function fixNum(num, len) {
    num |= 0;
github AdguardTeam / AdGuardForSafari / ElectronMainApp / src / utils / i18n.js View on Github external
return match;
            });

        // Looking for language match
        if (!fullMatch) {
            Object.keys(i18n.getCatalog())
                .some(key => {
                    const match = key.toLowerCase() === appLanguage.toLowerCase();
                    if (match) {
                        resultLocale = key;
                    }
                    return match;
                });
        }

        i18n.setLocale(resultLocale);
    };
github embark-framework / embark / src / lib / core / i18n / i18n.js View on Github external
function setOrDetectLocale(locale) {
  const how = locale ? 'specified' : 'detected';
  let _locale = locale || osLocale.sync();
  _locale = _locale.substr(0, 2);
  if (_locale && !isSupported(_locale)) {
    console.warn(`===== locale ${_locale} ${how} but not supported, default: en =====`.yellow);
    return;
  }
  return i18n.setLocale(_locale);
}
github actionhero / actionhero / src / modules / i18n.ts View on Github external
export function invokeConnectionLocale(connection: Connection) {
    const cmdParts = config.i18n.determineConnectionLocale.split(".");
    const method: Function = dotProp.get(i18n, cmdParts.join("."));
    const locale = method(connection);
    I18n.setLocale(connection, locale);
  }
github peeriodproject / core / src / core / App.ts View on Github external
setLocale: function (locale:string):void {
		i18n.setLocale(locale);
	},
github worknenjoy / gitpay / modules / mail / content.js View on Github external
Signatures.buttons = (language, buttons) => {
  i18n.setLocale(language || 'en')
  let secondary = ''
  if (buttons.secondary) {
    secondary = `
      <a style="padding: 8px 12px;border-radius: 2px;font-family: Helvetica, Arial, sans-serif;font-size: 14px; color: #ffffff;text-decoration: none;font-weight:bold;display: inline-block;" href="${buttons.secondary.url}">
          ${i18n.__(buttons.secondary.label)}             
      </a>
  `
  }
  return `

<table cellpadding="0" cellspacing="0" width="100%" style="margin-top: 20px">
  <tbody><tr>
      <td>
          <table cellpadding="0" cellspacing="20">
              <tbody><tr>
                  <td bgcolor="#009688" style="border-radius: 2px;"></td></tr></tbody></table></td></tr></tbody></table>
github davellanedam / node-express-mongodb-jwt-rest-api-skeleton / app / controllers / utils.js View on Github external
exports.sendResetPasswordEmailMessage = async (locale, user) => {
  i18n.setLocale(locale)
  const subject = i18n.__('forgotPassword.SUBJECT')
  const htmlMessage = i18n.__(
    'forgotPassword.MESSAGE',
    user.email,
    process.env.FRONTEND_URL,
    user.verification
  )
  const data = {
    user,
    subject,
    htmlMessage
  }
  const email = {
    subject,
    htmlMessage,
    verification: user.verification
github worknenjoy / gitpay / modules / mail / mail.js View on Github external
Sendmail.error = (user, subject, msg) => {
    const to = user.email
    const language = user.language || 'en'
    i18n.setLocale(language)
    request(
      to,
      subject,
      [
        {
          type: 'text/html',
          value: `${msg}
          ${Signatures.sign()}`
        },
      ]
    )
  }
}
github worknenjoy / gitpay / modules / tasks / removeAssignedUser.js View on Github external
.then(([ assign ]) => {
          const user = assign.User
          const language = user.language || 'en'
          i18n.setLocale(language)
          SendMail.success(
            assign.User,
            i18n.__('mail.assign.remove.subject'),
            i18n.__('mail.assign.remove.message', { message, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}`, title: task.title })
          )

          const ownerUser = author
          const ownerlanguage = ownerUser.language || 'en'
          i18n.setLocale(ownerlanguage)
          SendMail.success(
            ownerUser,
            i18n.__('mail.assign.remove.owner.subject'),
            i18n.__('mail.assign.remove.owner.message', { title: task.title, user: user.name || user.username, email: user.email, message: message, url: `${process.env.FRONTEND_HOST}/#/task/${task.id}}` })
          )
          return task.dataValues
        })