Skip to content

Commit

Permalink
可隐藏语言切换按钮,可设置默认语言
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyu2333 committed Nov 26, 2021
1 parent 22596dc commit 6287efc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/menu-bar/menu-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ class MenuBar extends React.Component {
/>
</div>
)}
{(this.props.canChangeLanguage) && (<div
{(this.props.canChangeLanguage &&
(window.scratchConfig && window.scratchConfig.menuBar && window.scratchConfig.menuBar.languageButton &&
window.scratchConfig.menuBar.languageButton.show)) && (<div
className={classNames(styles.menuBarItem, styles.hoverable, styles.languageMenu)}
>
<div>
Expand Down
12 changes: 11 additions & 1 deletion src/lib/app-state-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
let enhancer;

let initializedLocales = localesInitialState;
const locale = detectLocale(Object.keys(locales));
let locale;
if(window.scratchConfig && window.scratchConfig.menuBar && window.scratchConfig.menuBar.languageButton &&
window.scratchConfig.menuBar.languageButton.defaultLanguage){
window.scratchConfig.menuBar.languageButton.defaultLanguage
locale = window.scratchConfig.menuBar.languageButton.defaultLanguage
}else{
locale = detectLocale(Object.keys(locales));
}

if (locale !== 'en') {
initializedLocales = initLocale(initializedLocales, locale);
}
Expand Down Expand Up @@ -103,6 +111,8 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
var event = new CustomEvent('setFullScreen', {"detail": {isFullScreen: isFullScreen}});
document.dispatchEvent(event);
}


}
componentDidUpdate (prevProps) {
if (localesOnly) return;
Expand Down
5 changes: 5 additions & 0 deletions src/playground/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
style: {
background: 'hsla(215, 100%, 65%, 1)',
},
//切换语言按钮
languageButton:{
show: true, //是否显示
defaultLanguage: 'zh-cn' //默认语言 en zh-cn zh-tw
},
//新建按钮
newButton:{
show: true, //是否显示
Expand Down

0 comments on commit 6287efc

Please sign in to comment.