Closed zhllucky closed 1 year ago
this file can browse online in my browser. but can't use it in i18next-http-backend.
Please provide a reproducible example. I suspect you've a wrong config.
const HttpBackend = require('i18next-http-backend/cjs');
const fallbackLanguage = 'en';
const loadPath = https://cdn.simplelocalize.io/${projectToken}/_production/{{lng}}
;
module.exports = {
debug: true,
crossDomain: true,
withCredentials: false,
// load: 'languageOnly',
requestOptions: { method: 'GET', mode: 'no-cors', cache: 'default' },
backend: {
loadPath,
fallback: true,
ns: ['common'],
defaultNS: 'common',
fallbackLng: fallbackLanguage,
allowedAddOrUpdateHosts: ['localhost'],
crossDomain: true,
withCredentials: false,
requestOptions: { method: 'GET', mode: 'no-cors', cache: 'default', credentials: 'omit' },
backendOptions: [{ expirationTime: 60 * 60 * 1000 }], // 1 hour
backends:
typeof window !== 'undefined' ? [LocalStorageBackend, HttpBackend] : [],
parse: function (data) {
return JSON.parse(data);
},
}, i18n: { defaultLocale: 'en', locales: ['en', 'zh'], localeDetection: false, }, serializeConfig: false, };
this is my next-i18next.config.js
Yes, your config is not correct.
Try this:
const HttpBackend = require('i18next-http-backend/cjs')
const ChainedBackend= require('i18next-chained-backend').default
const LocalStorageBackend = require('i18next-localstorage-backend').default
const isBrowser = typeof window !== 'undefined'
const projectToken = '074d92066efb48f48b368a9dca89a69d'
const fallbackLanguage = 'en';
const loadPath = `https://cdn.simplelocalize.io/${projectToken}/_production/{{lng}}`;
module.exports = {
debug: true,
// load: 'languageOnly',
fallbackLng: fallbackLanguage,
ns: ['common'],
defaultNS: 'common',
backend: {
backendOptions: [
{ expirationTime: 60 * 60 * 1000 }, // 1 hour
{ loadPath }
],
backends: isBrowser ? [LocalStorageBackend, HttpBackend] : []
},
i18n: {
defaultLocale: 'en',
locales: ['en', 'zh'],
localeDetection: false,
},
serializeConfig: false,
use: isBrowser ? [ChainedBackend] : [],
};
btw: since you're using i18next... why don't you use locize instead of simplelocalize? With using locize you're helping the maintainers of i18next... because the creators of i18next are also the founders of locize: https://locize.com/i18next.html locize is the official sponsor of i18next.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
thanks. I use locize instead of simplelocalize. it work
i18next::backendConnector: loading namespace common for language zh failed [Error: ENOENT: no such file or directory, open 'https://cdn.simplelocalize.io/074d92066efb48f48b368a9dca89a69d/_production/zh']