process(handlerInput) { // Gets the locale from the request and initializes i18next. const localizationClient = i18n.init({ lng: handlerInput.requestEnvelope.request.locale, resources: languageStrings, returnObjects: true }); // Creates a localize function to support arguments. localizationClient.localize = function localize() { // gets arguments through and passes them to // i18next using sprintf to replace string placeholders // with arguments. const args = arguments; const value = i18n.t(...args); // If an array is used then a random value is selected if (Array.isArray(value)) { return value[Math.floor(Math.random() * value.length)]; } return value; }; // this gets the request attributes and save the localize function inside // it to be used in a handler by calling requestAttributes.t(STRING_ID, [args...]) const attributes = handlerInput.attributesManager.getRequestAttributes(); attributes.t = function translate(...args) { return localizationClient.localize(...args); } }
export function Players({ children }) { const { t } = useTranslation(); const classes = useStyles(); return ( <Paper square={true} elevation={1} className={classes.root}> <Typography className={classes.title} variant="h6"><PeopleIcon /> {t('Players')}</Typography> <List dense>{children}</List> </Paper> ); }
function getResourceBundle(lang, namespace = 'translation') { if (i18n.hasResourceBundle(lang, namespace)) { return i18n.getResourceBundle(lang, namespace); } else if (lang.includes("-")) { const newlang = lang.split("-")[0]; console.log(`no resource bundle found for ${lang} trying with ${newlang}`) return getResourceBundle(newlang, namespace); } console.log("no resource bundle found for " + lang) return {} }
describe('i18n', () => { it('should initate i18n', async () => { const t = await i18n; expect(t).toBeDefined(); }); it('should initate i18n with translations', async () => { const t = await i18n; expect( t(translations.feedbackFeature.description()).length, ).toBeGreaterThan(0); }); });
$.validator.addMethod('phoneFR', function(phone_number, element) { phone_number = phone_number.replace(/\(|\)|\s+|-/g, ''); return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(?:(?:(?:00\s?|\+)33\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/); }, i18next.t('Please enter a valid phone number'));
ipcMain.on('get-initial-translations', (event, arg) => { const loc = currentLocale; console.log('get-initial-translations: ' + loc); i18n.loadLanguages(loc, (err, t) => { const initial = {}; initial[loc] = { 'translation': getResourceBundle(loc, 'translation') } //const keys = Object.keys(initial[loc]['translation']) //console.log('get-initial-translations: ' + loc + " keys: " + keys.length); event.returnValue = initial; }); });
const initI18N = () => { i18next.init({ lng: getLanguage(), resources: messages }) }
Handlebars.registerHelper('paymentBadgeStatus', function() { var html = ''; if (this.status === 'paid') { html = '<span class="label label-success" data-toggle="tooltip" data-placement="bottom" title="'+i18next.t('Paid')+'"><i class="fa fa-check"></i> '+moment.monthsShort()[parseInt(this.month, 10)-1].toUpperCase()+'</span>'; } else if (this.status === 'partialypaid') { html = '<span class="label label-warning" data-toggle="tooltip" data-placement="bottom" title="'+i18next.t('Partially paid')+'"><i class="fa fa-exclamation-triangle"></i> '+moment.monthsShort()[parseInt(this.month, 10)-1].toUpperCase()+'</span>'; } else if (this.status === 'notpaid') { html = '<span class="label label-danger" data-toggle="tooltip" data-placement="bottom" title="'+i18next.t('Not paid')+'"><i class="fa fa-exclamation-triangle"></i> '+moment.monthsShort()[parseInt(this.month, 10)-1].toUpperCase()+'</span>'; } return new Handlebars.SafeString(html); });
_companyChanged($select) { var selection = $select.find(':selected').val(); if (selection === 'true') { $('#occupant-form .private-fields').hide(); $('#occupant-form .js-company-fields').show(); $('#occupant-form #manager-label').html(i18next.t('Effective manager (first and last name)')); } else { $('#occupant-form .js-company-fields').hide(); $('#occupant-form .private-fields').show(); $('#occupant-form #manager-label').html(i18next.t('First and last name')); } }
// Method helpers static get _Intl() { return { NumberFormat: new Intl.NumberFormat(i18next.language, { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }), NumberFormatPercent: new Intl.NumberFormat(i18next.language, { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }), NumberFormatCurrency: new Intl.NumberFormat(i18next.language, { style: 'currency', currency: i18next.t('__currency_code') }) }; }
const TranslatedCat = () => { const { t } = useTranslation(); return( <div> <p>{t('cat','meoww')}</p> </div> ) }
constructor(props) { super(props); i18n.on('languageChanged', (lng) => { // needed when language changes via path and to change path when language does not change via path rootStoreInstance.configStore.language = lng; rootStoreInstance.configStore.changeHistory(this.props.history, this.props.location); }); }
i18n.on('loaded', (loaded) => { //console.log('i18n-loaded'); createWindow(); i18n.changeLanguage(currentLocale); i18n.off('loaded'); });
// Update moment js locale when language is changed i18next.on("languageChanged", lng => { moment.locale(lng); });
const TranslatedDog=()=>{ const { t } = useTranslation(); return( <div> <p>{t('dog','woof')}</p> </div> ) }