Skip to content

Commit dba0622

Browse files
Merge pull request #325 from scratchfoundation/IPR-1063
feat: [IPR-1063] Add locale to editor state props
2 parents 28d26bc + a28aa46 commit dba0622

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,7 @@ jobs:
112112

113113
- name: Publish scratch-gui-standalone
114114
run: |
115-
jq '
116-
.name = "@scratch/scratch-gui-standalone" |
117-
del(.peerDependencies) |
118-
.exports."." = .exports."./standalone" |
119-
del(.exports."./standalone")
120-
' ./packages/scratch-gui/package.json | npx sponge ./packages/scratch-gui/package.json
115+
bash ./scripts/prepare-standalone-gui.sh
121116
122117
npm --workspace=@scratch/scratch-gui-standalone run clean && npm --workspace=@scratch/scratch-gui-standalone run build:dist-standalone
123118
npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-gui-standalone

packages/scratch-gui/src/exported-reducers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ScratchPaintReducer} from 'scratch-paint';
2-
import LocalesReducer, {localesInitialState, initLocale} from './reducers/locales.js';
2+
import LocalesReducer, {localesInitialState, initLocale, selectLocale} from './reducers/locales.js';
33
import GuiReducer, {buildInitialState, guiMiddleware, initEmbedded, initFullScreen, initPlayer} from './reducers/gui';
44
import {setFullScreen, setPlayer, setEmbedded} from './reducers/mode.js';
55
import {activateDeck} from './reducers/cards.js';
@@ -49,5 +49,6 @@ export {
4949
setFullScreen,
5050
setPlayer,
5151
setEmbedded,
52-
activateDeck
52+
activateDeck,
53+
selectLocale
5354
};

packages/scratch-gui/src/lib/app-state-provider-hoc.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
44

55
import {EditorState} from './editor-state';
66
import {setPlayer, setFullScreen, setEmbedded} from '../reducers/mode.js';
7-
import ConnectedIntlProvider from './connected-intl-provider.jsx';
87

98
/**
109
* Wraps the editor into the redux state contained within an EditorState instance.
@@ -39,11 +38,9 @@ export const AppStateProviderHOC = function (WrappedComponent) {
3938
} = this.props;
4039
return (
4140
<Provider store={appState.store}>
42-
<ConnectedIntlProvider>
43-
<WrappedComponent
44-
{...componentProps}
45-
/>
46-
</ConnectedIntlProvider>
41+
<WrappedComponent
42+
{...componentProps}
43+
/>
4744
</Provider>
4845
);
4946
}

packages/scratch-gui/src/lib/editor-state.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface EditorStateParams {
2121
isPlayerOnly?: boolean;
2222
showTelemetryModal?: boolean;
2323
isEmbedded?: boolean;
24+
locale?: string;
2425
}
2526

2627
/**
@@ -40,10 +41,22 @@ export class EditorState {
4041
let enhancer;
4142

4243
let initializedLocales = localesInitialState;
43-
const locale = detectLocale(Object.keys(locales));
44+
45+
let locale = 'en';
46+
if (params.locale) {
47+
if (Object.keys(locales).includes(params.locale)) {
48+
locale = params.locale;
49+
} else {
50+
console.warn(`Unsupported locale ${params.locale}, falling back to en`);
51+
}
52+
} else {
53+
locale = detectLocale(Object.keys(locales));
54+
}
55+
4456
if (locale !== 'en') {
4557
initializedLocales = initLocale(initializedLocales, locale);
4658
}
59+
4760
if (params.localesOnly) {
4861
// Used for instantiating minimal state for the unsupported
4962
// browser modal

scripts/prepare-standalone-gui.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
jq '
2+
if .name != "@scratch/scratch-gui-standalone" then
3+
.name = "@scratch/scratch-gui-standalone" |
4+
del(.peerDependencies) |
5+
.exports."." = .exports."./standalone" |
6+
del(.exports."./standalone")
7+
else
8+
.
9+
end
10+
' ./packages/scratch-gui/package.json | npx sponge ./packages/scratch-gui/package.json

0 commit comments

Comments
 (0)