Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(i18n): Change how duplicate values are stored to facilitate addi…
…ng new localizations.
  • Loading branch information
sangyuxiaowu committed Jul 21, 2022
commit ded5b37a4da52f15414bea6fe2f798a8fe6618a4
10 changes: 9 additions & 1 deletion src/main/services/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import i18next from 'i18next'
import Backend from 'i18next-fs-backend'
import { store } from '../../store'

const lng = store.preferences.get('language')

i18next.use(Backend).init({
fallbackLng: 'en',
lng: store.preferences.get('language'),
lng: lng,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to duplicate if prop is the same as the name of a local variable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I get it, I tried it and it works. 😀

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use just single lng

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to change a variable name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

{ lng: lng } equal { lng }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I see.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Learned new knowledge

debug: false,
ns: ['common', 'dialog', 'preferences', 'special', 'menu'],
defaultNS: 'common',
Expand All @@ -21,4 +23,10 @@ i18next.use(Backend).init({
}
})

i18next.addResourceBundle(lng, 'language', {
en: 'English',
ru: 'Русский',
zh_CN: '中文 (简体)'
})

export default i18next
5 changes: 1 addition & 4 deletions src/main/services/i18n/locales/en/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
}
},
"language": {
"label": "Language",
"en": "English",
"ru": "Русский",
"zh_CN": "简体中文"
"label": "Language"
}
}
5 changes: 1 addition & 4 deletions src/main/services/i18n/locales/ru/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
}
},
"language": {
"label": "Язык",
"en": "English",
"ru": "Русский",
"zh_CN": "简体中文"
"label": "Язык"
}
}
5 changes: 1 addition & 4 deletions src/main/services/i18n/locales/zh_CN/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
}
},
"language": {
"label": "语言",
"en": "English",
"ru": "Русский",
"zh_CN": "简体中文"
"label": "语言"
}
}
6 changes: 3 additions & 3 deletions src/renderer/components/preferences/LanguagePreferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ const localValue = computed({

const options = [
{
label: i18n.t('preferences:language.en'),
label: i18n.t('language:en'),
value: 'en'
},
{
label: i18n.t('preferences:language.ru'),
label: i18n.t('language:ru'),
value: 'ru'
},
{
label: i18n.t('preferences:language.zh_CN'),
label: i18n.t('language:zh_CN'),
value: 'zh_CN'
}
]
Expand Down