Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

how to add a new language file in both front-end and back-end ? #30

Open
changchichung opened this issue Nov 11, 2021 · 11 comments
Open
Labels
enhancement New feature or request

Comments

@changchichung
Copy link

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

2021-11-11 10:29:08 [changch@hqdc034 gofi-backend]$ go build 
go: downloading github.com/aviddiviner/gin-limit v0.0.0-20170918012823-43b5f79762c1
go: downloading github.com/gin-gonic/gin v1.7.4
go: downloading github.com/golang-jwt/jwt/v4 v4.0.0
go: downloading github.com/go-xorm/xorm v0.7.9
go: downloading github.com/mattn/go-sqlite3 v2.0.3+incompatible
go: downloading golang.org/x/text v0.3.7
go: downloading golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf
go: downloading github.com/gabriel-vasile/mimetype v1.3.1
go: downloading golang.org/x/tools v0.1.5
go: downloading xorm.io/builder v0.3.9
go: downloading xorm.io/core v0.7.3
go: downloading github.com/mattn/go-isatty v0.0.13
go: downloading github.com/go-playground/validator/v10 v10.9.0
go: downloading google.golang.org/protobuf v1.27.1
go: downloading golang.org/x/net v0.0.0-20210505024714-0287a6fb4125
go: downloading github.com/go-playground/universal-translator v0.18.0
go: downloading golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
go: downloading github.com/leodido/go-urn v1.2.1
go: downloading github.com/go-playground/locales v0.14.0
main.go:17:12: pattern dist/*: no matching files found

any suggestions ?

or is there any documents to explain how to do localization ?

@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

front-end: Gofi/gofi-frontend/src/i18n
back-end: Gofi/gofi-backend/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?

@Sloaix Sloaix added the enhancement New feature or request label Nov 11, 2021
@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

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.

@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

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.

@changchichung
Copy link
Author

Could you tell me which language you want to support?

ja-JP , zh-TW and fr-FR

@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

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 yarn && yarn build and make sure docker and node14 yarn are installed.

But it might be a little late because I'm leaving for a haircut in an hour.

@changchichung
Copy link
Author

well , I did try build locally .

yarn && yarn build error

Checking for required docker image techknowlogick/xgo:latest... found.
Cross compiling ./...
Enabled Go module support
Building /source/go.mod...
Compiling for darwin-10.12/amd64...
main.go:17:12: pattern dist/*: no matching files found
Compiling for darwin-10.12/arm64...
main.go:17:12: pattern dist/*: no matching files found
Cleaning up build environment...
chown: cannot access '/build/gofi*': No such file or directory
2021/11/11 15:06:23 Failed to cross compile package: exit status 1.
[15:06:23] Finished 'build-backend' after 5.58 min
[15:06:23] Starting 'after-build'...
[15:06:23] Finished 'after-build' after 1.64 ms
[15:06:23] Finished 'build' after 5.6 min
[15:06:23] Finished 'build-production' after 5.6 min
[15:06:23] Finished 'default' after 5.6 min
Done in 337.21s.

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 .

@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

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.

@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

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

@Sloaix
Copy link
Owner

Sloaix commented Nov 11, 2021

Clone latest code

You must clone latest code.

First translate the frontend

  • Copy /gofi-frontend/i18n/ zh-hans to zh-hant
  • Copy /gofi-frontend/i18n/zh-hans.ts to zh-hant.ts

After completion of translation, open /Gofi/gofi-frontend/src/i18n/index.ts file, add language pack for zh-Hant (Notice adding aliases for zh-Hant)

// /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 backend

Copy /Gofi/gofi-backend/i18n/zh_Hans.go to zh_Hant.go , after completion of translation, open /Gofi/gofi-backend/i18n/translate.go file to add language pack.

//  /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)
}

@changchichung
Copy link
Author

changchichung commented Nov 12, 2021

after doing some translating work , there's no way to select new lang files in Gofi UI

gofi version

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.

@Sloaix
Copy link
Owner

Sloaix commented Nov 13, 2021

well , I did try build locally .

yarn && yarn build error

Checking for required docker image techknowlogick/xgo:latest... found.
Cross compiling ./...
Enabled Go module support
Building /source/go.mod...
Compiling for darwin-10.12/amd64...
main.go:17:12: pattern dist/*: no matching files found
Compiling for darwin-10.12/arm64...
main.go:17:12: pattern dist/*: no matching files found
Cleaning up build environment...
chown: cannot access '/build/gofi*': No such file or directory
2021/11/11 15:06:23 Failed to cross compile package: exit status 1.
[15:06:23] Finished 'build-backend' after 5.58 min
[15:06:23] Starting 'after-build'...
[15:06:23] Finished 'after-build' after 1.64 ms
[15:06:23] Finished 'build' after 5.6 min
[15:06:23] Finished 'build-production' after 5.6 min
[15:06:23] Finished 'default' after 5.6 min
Done in 337.21s.

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 .

Fixed bug where no dist directory was found in the development environment causing build failure

main.go:17:12: pattern dist/*: no matching files found

see 16c28d4

If you want to try to develop or build locally , try:

  • under gofi-frontend, run yarn && yarn run dev
  • under gofi-backend, run go run main.go

Gofi frontend listens to port 3000, backend listens to port 8080, in the development environment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants