How to use the i18n.getCatalog 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 oliversalzburg / i18n-node-angular / i18n-node-routes.js View on Github external
var locale = request.params.locale;
		var phrase = request.params.phrase;

		var result;
		if( request.query.plural ) {
			var singular = phrase;
			var plural = request.query.plural;
			// Make sure the information is added to the catalog if it doesn't exist yet.
			var translated = i18n.__n( {
				singular : singular,
				plural   : plural,
				count    : request.query.count,
				locale   : locale
			} );
			// Retrieve the translation object from the catalog and return it.
			var catalog = i18n.getCatalog( locale );
			result = singular.split( configuration.objectNotation ).reduce( function( object, index ) {
				return object[ index ];
			}, catalog );

		} else {
			result = i18n.__( { phrase : phrase, locale : locale } );
		}
		response.send( result );
	}
};
github Terminal / discordapps.dev / src / routers / lang.js View on Github external
router.get('/', (req, res) => {
  // Send the list of selectable locales
  res.render('lang', {
    languages: Object.keys(i18n.getCatalog())
  });
})
  .get('/:lang', (req, res) => {
github AdguardTeam / AdGuardForSafari / ElectronMainApp / src / utils / i18n.js View on Github external
const appLanguage = appLocale.substr(0, 2);
        let resultLocale = 'en';

        // Looking for locale match
        const fullMatch = Object.keys(i18n.getCatalog())
            .some(key => {
                const match = key.replace(/-/g, '_').toLowerCase() === appLocale.replace(/-/g, '_').toLowerCase();
                if (match) {
                    resultLocale = key;
                }
                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 nahuelcandia / mobile-app-maker / lib / i18n / index.js View on Github external
app.use('*', function(req, res, next) {
    var catalogs = i18n.getCatalog();

    app.locals.lang = catalogs[req.locale];
    next();
  });
}
github alphagov / pay-frontend / app / middleware / resolve_language.js View on Github external
module.exports = function (req, res, next) {
  const language = req.chargeData.language || 'en'
  i18n.setLocale(req, language)
  res.locals.translationStrings = JSON.stringify(i18n.getCatalog(language))
  res.locals.language = language
  next()
}
github 7coil / discordmail / server / discord / cogs / locale / index.js View on Github external
module.exports.command = (message) => {
	if (message.input && Object.keys(i18n.getCatalog()).includes(message.input)) {
		r.table('i18n')
			.insert({
				id: message.inbox,
				lang: message.input
			}, {
				conflict: 'update'
			})
			.run(r.conn, (err) => {
				if (err) {
					message.channel.createMessage(message.__('err_generic'));
				} else {
					message.setLocale(message.input);
					message.channel.createMessage(message.__('locale_set', { locale: message.input }));
				}
			});
	} else {
github 7coil / discordmail / server / lang.js View on Github external
router.get('/', (req, res) => {
	res.render('lang.pug', {
		title: 'Languages',
		languages: Object.keys(i18n.getCatalog())
	});
})
	.get('/:lang', (req, res) => {
github 7coil / discordmail / server / discord / cogs / system.js View on Github external
command: async (message) => {
		if (message.mss.input && Object.keys(i18n.getCatalog()).includes(message.mss.input)) {
			await r.table('i18n')
				.insert({
					id: message.author.id,
					lang: message.mss.input
				}, {
					conflict: 'update'
				});
			message.setLocale(message.mss.input);
			message.channel.createMessage(message.__('locale_set', { locale: message.__(`lang_${message.mss.input.replace(/-/g, '_')}`) }));
		} else {
			message.channel.createMessage(`${message.__('locale_incorrect')}\n${Object.keys(i18n.getCatalog()).map(lang => `\`${lang}\` - ${message.__(`lang_${lang.replace(/-/g, '_')}`)}`).join('\n')}`);
		}
	}
}, {
github mautic / documentation / lib / utils / i18n.js View on Github external
function getCatalog(locale) {
    locale = normalizeLanguage(locale);
    return i18n.getCatalog(locale);
}
github Terminal / discordapps.dev / src / discord / cogs / system.js View on Github external
command: (message) => {
    if (message.mss.input && Object.keys(i18n.getCatalog()).includes(message.mss.input)) {
      r.table('i18n')
        .insert({
          id: message.author.id,
          lang: message.mss.input
        }, {
          conflict: 'update'
        })
        .run();
      message.setLocale(message.mss.input);
      message.channel.createMessage(message.__('locale_set', { locale: message.__(`lang_${message.mss.input}`) }));
    } else {
      message.channel.createMessage(`${message.__('locale_incorrect')}\n${Object.keys(i18n.getCatalog()).map(lang => `\`${lang}\` - ${message.__(`lang_${lang}`)}`).join('\n')}`);
    }
  }
}, {