How to use cp-translations - 6 common examples

To help you get started, we’ve selected a few cp-translations 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 CoderDojo / cp-zen-platform / web / lib / fn / i18n-translate.js View on Github external
const I18NHelper = require('cp-i18n-lib');
const CpTranslations = require('cp-translations');

const i18nHelper = new I18NHelper({
  poFilePath: CpTranslations.getPoFilePath(),
  poFileName: 'messages.po',
  domain: 'coder-dojo-platform',
});

module.exports = function(locale, params) {
  let translation = i18nHelper.getClosestTranslation(locale, params.key);
  if (translation) {
    if (params.context) {
      translation = translation.withContext(params.context);
    }
    translation = params.count // eslint-disable-line no-nested-ternary
      ? translation.ifPlural(params.count, params.key).fetch(params.count)
      : params.var
      ? translation.fetch(params.var)
      : translation.fetch();
  } else {
github CoderDojo / cp-dojos-service / email-notifications.js View on Github external
function send_notification (args, done) {
    var subject = args.subject;
    var bypassTranslation = args.bypassTranslation;
    var subjectVariables = args.subjectVariables || [];
    var subjectTranslation;
    var emailCode;
    var locale = args.locality;
    var code = args.code;
    var i18nHelper = new I18NHelper({
      poFilePath: CpTranslations.getPoFilePath(),
      poFileName: 'messages.po',
      domain: 'coder-dojo-platform'
    });

    if (options.sendemail && options.email) {
      logger.warn('email-notifications', JSON.stringify(args));
      emailCode = code + locale;
      if (!fs.existsSync(CpTranslations.getEmailTemplatePath(emailCode))) emailCode = code + 'en_US';
      if (!args.to) return done(null, {ok: false, why: 'No recipient set.'});

      if (!bypassTranslation) {
        subjectTranslation = i18nHelper.getClosestTranslation(locale, subject);
        if (subjectTranslation === null) {
          logger.warn('email-notifications', JSON.stringify({
            ok: false,
            why: 'Invalid email subject.',
github CoderDojo / cp-zen-platform / web / controllers / locale / index.js View on Github external
handler(request, reply) {
      let locale =
        (request.query && request.query.lang) ||
        (request.app && request.app.context && request.app.context.locality) ||
        'en_US';
      locale = formatLocaleCode(locale);
      if (!fs.existsSync(CpTranslations.getPoFilePath('messages.po', locale))) {
        locale = 'en_US';
      }
      const format = request.query.format || 'jed';
      po2json.parseFile(
        CpTranslations.getPoFilePath('messages.po', locale),
        {
          format,
          domain: 'coder-dojo-platform',
        },
        reply
      );
    },
  },
github CoderDojo / cp-zen-platform / web / controllers / locale / index.js View on Github external
handler(request, reply) {
      let locale =
        (request.query && request.query.lang) ||
        (request.app && request.app.context && request.app.context.locality) ||
        'en_US';
      locale = formatLocaleCode(locale);
      if (!fs.existsSync(CpTranslations.getPoFilePath('messages.po', locale))) {
        locale = 'en_US';
      }
      const format = request.query.format || 'jed';
      po2json.parseFile(
        CpTranslations.getPoFilePath('messages.po', locale),
        {
          format,
          domain: 'coder-dojo-platform',
        },
        reply
      );
    },
  },
github CoderDojo / cp-dojos-service / email-notifications.js View on Github external
var bypassTranslation = args.bypassTranslation;
    var subjectVariables = args.subjectVariables || [];
    var subjectTranslation;
    var emailCode;
    var locale = args.locality;
    var code = args.code;
    var i18nHelper = new I18NHelper({
      poFilePath: CpTranslations.getPoFilePath(),
      poFileName: 'messages.po',
      domain: 'coder-dojo-platform'
    });

    if (options.sendemail && options.email) {
      logger.warn('email-notifications', JSON.stringify(args));
      emailCode = code + locale;
      if (!fs.existsSync(CpTranslations.getEmailTemplatePath(emailCode))) emailCode = code + 'en_US';
      if (!args.to) return done(null, {ok: false, why: 'No recipient set.'});

      if (!bypassTranslation) {
        subjectTranslation = i18nHelper.getClosestTranslation(locale, subject);
        if (subjectTranslation === null) {
          logger.warn('email-notifications', JSON.stringify({
            ok: false,
            why: 'Invalid email subject.',
            args
          }));
          return done(null, {ok: false, why: 'Invalid email subject.'});
        }
        subject = subjectTranslation.fetch(subjectVariables);
      }
      seneca.act({
        role: 'mail', cmd: 'send',
github CoderDojo / cp-dojos-service / config / config.js View on Github external
};
  }

  return {
    'postgresql-store': pgConfig(),
    'google-api': googleApiConfig(),
    'kue': kueConfig(),
    'email-notifications': {
      sendemail: true,
      sendFrom: 'The CoderDojo Team ',
      email: {
        headers: {'X-SMTPAPI': '{"category": ["cp-dojos-service"]}'}
      }
    },
    maildev: {
      folder: path.resolve(CpTranslations.getEmailTemplatePath()),
      mail: {
        from: 'no-reply@coderdojo.com'
      },
      config: {
        host: 'maildev',
        port: 25,
        ignoreTLS: true
      }
    },
    email: {
      folder: path.resolve(CpTranslations.getEmailTemplatePath()),
      config: {
        pool: true,
        service: 'sendgrid',
        auth: {
          user: process.env.MAIL_USER,

cp-translations

Translations for the CoderDojo Community Platform

MIT
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis