-
Notifications
You must be signed in to change notification settings - Fork 51
how to add a new language file in both front-end and back-end ? #30
Comments
front-end: Gofi/gofi-frontend/src/i18n Currently, the multi-language support is not perfect. Besides modifying the translation files, we also need to modify the code. Could you tell me which language you want to support? |
A few minutes ago, i migrated the router from reach router to react router V6. In the next time, I can try to add the language you want gofi to support. |
I plan to improve the document tomorrow, but I need to upgrade a latest docker image tag for master branch to match the new document. |
ja-JP , zh-TW and fr-FR |
I will try to refactor the i18n part of the code today to support localized translation files. I will reply you after all the preparation work to support other languages is completed. Then you can start localizing. If you want to try to build locally, clone Gofi master branch first , then run But it might be a little late because I'm leaving for a haircut in an hour. |
well , I did try build locally . yarn && yarn build error
I have to download from beta release eand extract the dist folder. but with the new binary , I only see a blank page , and no error message in console. I will wait for your next release . |
Since many countries and regions use Simplified Chinese and Traditional Chinese, I will refactor the code for the multi-language section and divide it according to language rather than country. The country flag of language selector will be removed. zh-Hans for Simplified Chinese, and zh-Hant for Traditional Chinese. |
You can run the latest gofi from the master branch via docker docker run -d \
--name=gofi \
-p 80:8080 \
-v ~/gofi:/app \
-v ~/gofi/storage:/app/storage \
--restart unless-stopped \
sloaix/gofi:nightly-prod-latest and you can find latest build from Gofi-nightly-build,or latest docker image from Docker Hub |
Clone latest codeYou must clone latest code. First translate the frontend
After completion of translation, open // /Gofi/gofi-frontend/src/i18n/index.ts
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import en from './en'
import zhHans from './zh-Hans'
// import zhHant from './zh-Hant'
const resources = {
en: {
translation: en,
},
'zh-Hans': {
translation: zhHans,
},
// alias for zh-Hans
'zh-CN': {
translation: zhHans,
},
// alias for zh-Hans
'zh-SG': {
translation: zhHans,
},
// 'zh-Hant': {
// translation: zhHant,
// },
// // alias for zh-Hant
// 'zh-TW': {
// translation: zhHant,
// },
// // alias for zh-Hant
// 'zh-HK': {
// translation: zhHant,
// }
}
i18n.use(initReactI18next).init({
resources: resources,
lng: 'en',
fallbackLng: 'en',
interpolation: {
escapeValue: false,
},
})
export default i18n Second translate the backendCopy // /Gofi/gofi-backend/i18n/translate.go
func init() {
for _, key := range TranslateKeys {
// add translation pack
_ = message.SetString(language.TraditionalChinese, key.String(), ZhHant[key])
_ = message.SetString(language.SimplifiedChinese, key.String(), ZhHans[key])
_ = message.SetString(language.English, key.String(), En[key])
}
printer = message.NewPrinter(language.Chinese)
} |
after doing some translating work , there's no way to select new lang files in Gofi UI UPDATE: edit gofi-frontend/src/components/layouts/MainLayout/LangSelect.tsx , add the languages just been translated . (not mentioned above ) and re-compile again. and also don't forget to edit gofi-frontend/src/pages/file/FileViewer.tsx , the messages here does not include in the lang pack. |
Fixed bug where no dist directory was found in the development environment causing build failure
see 16c28d4 If you want to try to develop or build locally , try:
Gofi frontend listens to port 3000, backend listens to port 8080, in the development environment. |
I add a language file in Gofi/gofi-frontend/src/i18n , and Gofi/gofi-backend/i18n
but when I try to go build , there's some error like
any suggestions ?
or is there any documents to explain how to do localization ?
The text was updated successfully, but these errors were encountered: