Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: i18n init done fires even with lang load error #2650

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const getCtx = require('./context')
module.exports = async function () {
const ctx = getCtx()
logger.info('[i18n] init...')
const lng = store.get('language')
logger.info(`[i18n] configured language: ${lng}`)
await i18n
// @ts-expect-error
.use(ICU)
.use(Backend)
.init({
lng: store.get('language'),
lng,
fallbackLng: {
'zh-Hans': ['zh-CN', 'en'],
'zh-Hant': ['zh-TW', 'en'],
Expand All @@ -29,8 +31,14 @@ module.exports = async function () {
},
(err, t) => {
if (err) {
logger.error('[i18n] init failed', err)
return
/**
* even if an error occurs here, i18n still may work properly.
* e.g. https://github.com/ipfs/ipfs-desktop/issues/2627
* Language's of "en-US" or "zh" may not exist at `join(__dirname, '../assets/locales/{{lng}}.json')` but i18next loads
* the appropriate language file with/without the region code. Partially discussed at https://github.com/i18next/i18next/issues/964
*/
logger.error('[i18n] init error')
logger.error(err)
Comment on lines +40 to +41
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual Error was not being logged for some reason... error files and logging patterns need a serious look

}
logger.info('[i18n] init done')
ctx.setProp('i18n.initDone', true)
Expand Down