From b7668b4e9c3b64497977dca926d8b6953c07e712 Mon Sep 17 00:00:00 2001 From: Minfee <39008983+Minfee@users.noreply.github.com> Date: Mon, 13 Dec 2021 13:44:17 +0800 Subject: [PATCH] fix(formily): set default language (#163) Auto sets the language to Chinese when the browser's language does not match in preset language. --- examples/basic/src/main.tsx | 55 +++++++++++-------- examples/sandbox/src/main.tsx | 54 ++++++++++-------- .../antd/playground/widgets/ActionsWidget.tsx | 6 ++ .../next/playground/widgets/ActionsWidget.tsx | 6 ++ 4 files changed, 75 insertions(+), 46 deletions(-) diff --git a/examples/basic/src/main.tsx b/examples/basic/src/main.tsx index cbd8f349f..66f33af65 100644 --- a/examples/basic/src/main.tsx +++ b/examples/basic/src/main.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import ReactDOM from 'react-dom' import { Designer, @@ -298,28 +298,37 @@ const Logo: React.FC = () => ( ) -const Actions = observer(() => ( - - { - GlobalRegistry.setDesignerLanguage(e.target.value) - }} - /> - - - - -)) +const Actions = observer(() => { + const supportLocales = ['zh-cn', 'en-us', 'ko-kr'] + useEffect(() => { + if (!supportLocales.includes(GlobalRegistry.getDesignerLanguage())) { + GlobalRegistry.setDesignerLanguage('zh-cn') + } + }, []) + + return ( + + { + GlobalRegistry.setDesignerLanguage(e.target.value) + }} + /> + + + + + ) +}) const engine = createDesigner() const App = () => { diff --git a/examples/sandbox/src/main.tsx b/examples/sandbox/src/main.tsx index bd7f325cf..f1267f192 100644 --- a/examples/sandbox/src/main.tsx +++ b/examples/sandbox/src/main.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import ReactDOM from 'react-dom' import { Designer, @@ -297,28 +297,36 @@ const Logo: React.FC = () => ( ) -const Actions = observer(() => ( - - { - GlobalRegistry.setDesignerLanguage(e.target.value) - }} - /> - - - - -)) +const Actions = observer(() => { + const supportLocales = ['zh-cn', 'en-us', 'ko-kr'] + useEffect(() => { + if (!supportLocales.includes(GlobalRegistry.getDesignerLanguage())) { + GlobalRegistry.setDesignerLanguage('zh-cn') + } + }, []) + return ( + + { + GlobalRegistry.setDesignerLanguage(e.target.value) + }} + /> + + + + + ) +}) const engine = createDesigner() const App = () => { diff --git a/formily/antd/playground/widgets/ActionsWidget.tsx b/formily/antd/playground/widgets/ActionsWidget.tsx index bb89688a8..dbfb55d35 100644 --- a/formily/antd/playground/widgets/ActionsWidget.tsx +++ b/formily/antd/playground/widgets/ActionsWidget.tsx @@ -11,6 +11,12 @@ export const ActionsWidget = observer(() => { useEffect(() => { loadInitialSchema(designer) }, []) + const supportLocales = ['zh-cn', 'en-us', 'ko-kr'] + useEffect(() => { + if (!supportLocales.includes(GlobalRegistry.getDesignerLanguage())) { + GlobalRegistry.setDesignerLanguage('zh-cn') + } + }, []) return (