Modernizes the whole i18n stack:
- 48 translate([], {wait:true}) / translate() HOCs -> withTranslation()
- react.wait:true -> react.useSuspense:false
- whitelist -> supportedLngs; added compatibilityJSON: 'v3' so our
natural-language keys + v3 _plural layout keep working (custom
separators ss/eth/dj preserved)
- backends: xhr -> i18next-http-backend (client), sync-fs ->
i18next-fs-backend (server); dropped i18next-localstorage-cache
(was enabled:false); languagedetector 2 -> 8
- ReSendEmail: <Interpolate> (removed in v10) -> <Trans values={{email}}/>,
dropped the removed bare t export
- saveMissing handler signature (lngs, ns, key, fallbackValue)
Silences the per-component Translate/I18n legacy-context warnings.
Browser-verified es/en switch and <Trans> interpolation on /fires;
REST smoke byte-identical.
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import moment from 'moment';
|
|
// Load the js langs
|
|
import es from 'meteor-accounts-t9n/build/es';
|
|
import en from 'meteor-accounts-t9n/build/en';
|
|
// TODO ask for translation of this
|
|
// import gl from 'meteor-accounts-t9n/build/gl';
|
|
|
|
const backOpts = {
|
|
// path where resources get loaded from
|
|
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
|
|
|
// path to post missing resources
|
|
addPath: '/locales/{{lng}}/{{ns}}.missing.json',
|
|
|
|
// jsonIndent to use when storing json files
|
|
jsonIndent: 2
|
|
};
|
|
|
|
const forceDebug = true;
|
|
const shouldDebug = (forceDebug && !Meteor.isProduction);
|
|
|
|
const i18nOpts = {
|
|
backend: backOpts,
|
|
// lng: 'es',
|
|
fallbackLng: {
|
|
gl: ['es'],
|
|
default: ['en']
|
|
},
|
|
sendMissingTo: 'fallback',
|
|
interpolation: {
|
|
escapeValue: false, // not needed for react!!
|
|
formatSeparator: ',',
|
|
format: function f(value, format, lng) {
|
|
// https://www.i18next.com/formatting.html
|
|
// console.log(`Value: ${value} with format: ${format} to lang: ${lng}`);
|
|
if (format === 'uppercase') return value.toUpperCase();
|
|
if (value instanceof Date) return moment(value).format(format);
|
|
if (format === 'number') return Intl.NumberFormat(lng).format(value);
|
|
return value;
|
|
}
|
|
},
|
|
supportedLngs: ['es', 'en', 'gl'], // allowed languages (was `whitelist` pre-i18next-21)
|
|
load: 'languageOnly', // 'es' o 'en', previously: 'all', // es-ES -> es, en-US -> en
|
|
debug: shouldDebug,
|
|
ns: 'common',
|
|
defaultNS: 'common',
|
|
saveMissing: shouldDebug, // if true seems it's fails to getResourceBundle
|
|
saveMissingTo: 'es',
|
|
// Our locale JSON uses natural-language (Spanish) keys and the v3 plural
|
|
// layout (`key_plural`), so keep i18next on the v3 JSON format instead of
|
|
// the v4 suffix scheme (`key_one`/`key_other`).
|
|
compatibilityJSON: 'v3',
|
|
keySeparator: 'ß',
|
|
nsSeparator: 'ð',
|
|
pluralSeparator: 'đ'
|
|
};
|
|
|
|
export default i18nOpts;
|