Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: add getInstallLanguageConfig

sy-recordsc751364974a9
diff --git a/cmd/answer/main.go b/cmd/answer/main.go
deleted file mode 100644
index fb91f594..00000000
--- a/cmd/answer/main.go
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-//go:generate go run github.com/swaggo/swag/cmd/swag init -g ./cmd/answer/main.go -d ../../ -o ../../docs
-
-package main
-
-import (
- answercmd "github.com/apache/incubator-answer/cmd"
-)
-
-// main godoc
-// @title "apache answer"
-// @description = "apache answer api"
-// @version = "v0.0.1"
-// @BasePath = "/"
-// @securityDefinitions.apikey ApiKeyAuth
-// @in header
-// @name Authorization
-func main() {
- answercmd.Main()
-}
diff --git a/docs/docs.go b/docs/docs.go
index 7f5bd871..32942b7d 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -7226,6 +7226,35 @@ const docTemplate = `{
}
}
},
+ "/installation/language/config": {
+ "get": {
+ "description": "get installation language config mapping",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Lang"
+ ],
+ "summary": "get installation language config mapping",
+ "parameters": [
+ {
+ "type": "string",
+ "description": "Accept-Language",
+ "name": "Accept-Language",
+ "in": "header",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/installation/language/options": {
"get": {
"description": "get installation language options",
diff --git a/docs/swagger.json b/docs/swagger.json
index 093e0dfc..3aa86c6b 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -7200,6 +7200,35 @@
}
}
},
+ "/installation/language/config": {
+ "get": {
+ "description": "get installation language config mapping",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Lang"
+ ],
+ "summary": "get installation language config mapping",
+ "parameters": [
+ {
+ "type": "string",
+ "description": "Accept-Language",
+ "name": "Accept-Language",
+ "in": "header",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/installation/language/options": {
"get": {
"description": "get installation language options",
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 6d96c8a1..4188b6c0 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -7239,6 +7239,25 @@ paths:
summary: init environment
tags:
- installation
+ /installation/language/config:
+ get:
+ description: get installation language config mapping
+ parameters:
+ - description: Accept-Language
+ in: header
+ name: Accept-Language
+ required: true
+ type: string
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ summary: get installation language config mapping
+ tags:
+ - Lang
/installation/language/options:
get:
description: get installation language options
diff --git a/internal/install/install_controller.go b/internal/install/install_controller.go
index 7f57efbf..05f7daa6 100644
--- a/internal/install/install_controller.go
+++ b/internal/install/install_controller.go
@@ -20,6 +20,7 @@
package install
import (
+ "encoding/json"
"net/http"
"os"
"path/filepath"
@@ -37,6 +38,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/i18n"
"github.com/segmentfault/pacman/log"
)
@@ -51,6 +53,18 @@ func LangOptions(ctx *gin.Context) {
handler.HandleResponse(ctx, nil, translator.LanguageOptions)
}
+// GetLangMapping get installation language config mapping
+// @Summary get installation language config mapping
+// @Description get installation language config mapping
+// @Tags Lang
+// @Param Accept-Language header string true "Accept-Language"
+// @Produce json
+// @Success 200 {object} handler.RespBody{}
+// @Router /installation/language/config [get]
+func GetLangMapping(ctx *gin.Context) {
+ // TODO
+}
+
// CheckConfigFileAndRedirectToInstallPage if config file not exist try to redirect to install page
// @Summary if config file not exist try to redirect to install page
// @Description if config file not exist try to redirect to install page
diff --git a/internal/install/install_server.go b/internal/install/install_server.go
index f6087fea..76a2fffe 100644
--- a/internal/install/install_server.go
+++ b/internal/install/install_server.go
@@ -64,6 +64,7 @@ func NewInstallHTTPServer() *gin.Engine {
installApi.GET(c.UI.BaseURL+"/", CheckConfigFileAndRedirectToInstallPage)
installApi.GET(c.UI.BaseURL+"/install", WebPage)
installApi.GET(c.UI.BaseURL+"/50x", WebPage)
+ installApi.GET("/installation/language/config", GetLangMapping)
installApi.GET("/installation/language/options", LangOptions)
installApi.POST("/installation/db/check", CheckDatabase)
installApi.POST("/installation/config-file/check", CheckConfigFile)
diff --git a/internal/service/mock/siteinfo_repo_mock.go b/internal/service/mock/siteinfo_repo_mock.go
index abc1fe07..cdc72b80 100644
--- a/internal/service/mock/siteinfo_repo_mock.go
+++ b/internal/service/mock/siteinfo_repo_mock.go
@@ -1,22 +1,3 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
// Code generated by MockGen. DO NOT EDIT.
// Source: ./siteinfo_service.go
diff --git a/ui/src/i18n/init.ts b/ui/src/i18n/init.ts
index 59ffaf46..919335cb 100644
--- a/ui/src/i18n/init.ts
+++ b/ui/src/i18n/init.ts
@@ -21,20 +21,6 @@ import { initReactI18next } from 'react-i18next';
import i18next from 'i18next';
import en_US from '@i18n/en_US.yaml';
-import es_ES from '@i18n/es_ES.yaml';
-import pt_BR from '@i18n/pt_BR.yaml';
-import pt_PT from '@i18n/pt_PT.yaml';
-import de_DE from '@i18n/de_DE.yaml';
-import fr_FR from '@i18n/fr_FR.yaml';
-import ja_JP from '@i18n/ja_JP.yaml';
-import it_IT from '@i18n/it_IT.yaml';
-import ru_RU from '@i18n/ru_RU.yaml';
-import zh_CN from '@i18n/zh_CN.yaml';
-import zh_TW from '@i18n/zh_TW.yaml';
-import ko_KR from '@i18n/ko_KR.yaml';
-import vi_VN from '@i18n/vi_VN.yaml';
-import sk_SK from '@i18n/sk_SK.yaml';
-import fa_IR from '@i18n/fa_IR.yaml';
import { DEFAULT_LANG, LANG_RESOURCE_STORAGE_KEY } from '@/common/constants';
import Storage from '@/utils/storage';
@@ -47,48 +33,6 @@ const initResources = {
en_US: {
translation: en_US.ui,
},
- es_ES: {
- translation: es_ES.ui,
- },
- pt_BR: {
- translation: pt_BR.ui,
- },
- pt_PT: {
- translation: pt_PT.ui,
- },
- de_DE: {
- translation: de_DE.ui,
- },
- fr_FR: {
- translation: fr_FR.ui,
- },
- ja_JP: {
- translation: ja_JP.ui,
- },
- it_IT: {
- translation: it_IT.ui,
- },
- ru_RU: {
- translation: ru_RU.ui,
- },
- zh_CN: {
- translation: zh_CN.ui,
- },
- zh_TW: {
- translation: zh_TW.ui,
- },
- ko_KR: {
- translation: ko_KR.ui,
- },
- vi_VN: {
- translation: vi_VN.ui,
- },
- sk_SK: {
- translation: sk_SK.ui,
- },
- fa_IR: {
- translation: fa_IR.ui,
- },
};
const storageLang = Storage.get(LANG_RESOURCE_STORAGE_KEY);
diff --git a/ui/src/pages/Install/components/FirstStep/index.tsx b/ui/src/pages/Install/components/FirstStep/index.tsx
index 547e91c7..cb79fdfb 100644
--- a/ui/src/pages/Install/components/FirstStep/index.tsx
+++ b/ui/src/pages/Install/components/FirstStep/index.tsx
@@ -24,6 +24,7 @@ import { useTranslation } from 'react-i18next';
import type { LangsType, FormValue, FormDataType } from '@/common/interface';
import Progress from '../Progress';
import { getInstallLangOptions } from '@/services';
+import { setupInstallLanguage } from '@/utils/localize';
interface Props {
data: FormValue;
@@ -32,7 +33,7 @@ interface Props {
visible: boolean;
}
const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {
- const { t, i18n } = useTranslation('translation', { keyPrefix: 'install' });
+ const { t } = useTranslation('translation', { keyPrefix: 'install' });
const [langs, setLangs] = useState<LangsType[]>();
@@ -65,7 +66,7 @@ const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {
value={data.value}
isInvalid={data.isInvalid}
onChange={(e) => {
- i18n.changeLanguage(e.target.value);
+ setupInstallLanguage(e.target.value);
changeCallback({
lang: {
value: e.target.value,
diff --git a/ui/src/pages/Install/index.tsx b/ui/src/pages/Install/index.tsx
index c34a6e3d..4b43889a 100644
--- a/ui/src/pages/Install/index.tsx
+++ b/ui/src/pages/Install/index.tsx
@@ -37,6 +37,7 @@ import {
} from '@/utils';
import { CURRENT_LANG_STORAGE_KEY } from '@/common/constants';
import { BASE_ORIGIN } from '@/router/alias';
+import { setupInstallLanguage } from '@/utils/localize';
import {
FirstStep,
@@ -47,7 +48,7 @@ import {
} from './components';
const Index: FC = () => {
- const { t, i18n } = useTranslation('translation', { keyPrefix: 'install' });
+ const { t } = useTranslation('translation', { keyPrefix: 'install' });
const [step, setStep] = useState(1);
const [loading, setLoading] = useState(true);
const [errorData, setErrorData] = useState<{ [propName: string]: any }>({
@@ -293,7 +294,7 @@ const Index: FC = () => {
useEffect(() => {
configYmlCheck();
- i18n.changeLanguage(Storage.get(CURRENT_LANG_STORAGE_KEY));
+ setupInstallLanguage(Storage.get(CURRENT_LANG_STORAGE_KEY));
}, []);
if (loading) {
diff --git a/ui/src/services/install/index.ts b/ui/src/services/install/index.ts
index 70e581a2..b4b7dc0e 100644
--- a/ui/src/services/install/index.ts
+++ b/ui/src/services/install/index.ts
@@ -38,3 +38,7 @@ export const installBaseInfo = (params) => {
export const getInstallLangOptions = () => {
return request.get('/installation/language/options');
};
+
+export const getInstallLanguageConfig = () => {
+ return request.get('/installation/language/config');
+};
diff --git a/ui/src/utils/localize.ts b/ui/src/utils/localize.ts
index eea132a8..f446922c 100644
--- a/ui/src/utils/localize.ts
+++ b/ui/src/utils/localize.ts
@@ -35,6 +35,7 @@ import {
} from '@/common/constants';
import {
getAdminLanguageOptions,
+ getInstallLanguageConfig,
getLanguageConfig,
getLanguageOptions,
} from '@/services';
@@ -61,6 +62,15 @@ export const loadLanguageOptions = async (forAdmin = false) => {
};
const pullLanguageConf = (res) => {
+ if (window.location.pathname === '/install') {
+ return getInstallLanguageConfig().then((langConf) => {
+ if (langConf && langConf.ui) {
+ res.resources = langConf.ui;
+ Storage.set(LANG_RESOURCE_STORAGE_KEY, res);
+ }
+ });
+ }
+
return getLanguageConfig().then((langConf) => {
if (langConf && langConf.ui) {
res.resources = langConf.ui;
@@ -68,6 +78,7 @@ const pullLanguageConf = (res) => {
}
});
};
+
const addI18nResource = async (langName) => {
const res = { lng: langName, resources: undefined };
const storageResource = Storage.get(LANG_RESOURCE_STORAGE_KEY);
@@ -149,3 +160,9 @@ export const setupAppTheme = () => {
const theme = getCurrentTheme();
changeTheme(theme);
};
+
+export const setupInstallLanguage = async (lang) => {
+ await addI18nResource(lang);
+ localeDayjs(lang);
+ i18next.changeLanguage(lang);
+};