Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playground block: Add initial i18n support #197

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/wordpress-playground-block/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": ["file:./style-index.css", "wp-components"],
"viewScript": ["file:./view.js", "react", "react-dom", "wp-components"],
"viewScript": [
"file:./view.js",
"react",
"react-dom",
"wp-components",
"wp-i18n"
],
"render": "file:./render.php"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
__experimentalInputControl as InputControl,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

interface FileNameModalProps {
title: string;
Expand Down Expand Up @@ -39,7 +40,7 @@ export function FileNameModal({
/>
<br />
<Button variant="primary" type="submit">
Done
{__('Done', 'interactive-code-block')}
</Button>
</form>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
phpVar,
// @ts-ignore
} from 'https://playground.wordpress.net/client/index.js';
import { __ } from '@wordpress/i18n';

export default async function downloadZippedPlugin(client: PlaygroundClient) {
const docroot = await client.documentRoot;
Expand Down Expand Up @@ -50,7 +51,7 @@ async function zipPlaygroundFiles(client: PlaygroundClient, path: string) {
`,
});
if (result.text !== 'done') {
console.log('Error creating zip file');
console.log(__('Error creating zip file', 'interactive-code-block'));
console.log(result.errors);
console.log(result.text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { LanguageSupport } from '@codemirror/language';
import { writePluginFiles } from './write-plugin-files';
import downloadZippedPlugin from './download-zipped-plugin';
import classnames from 'classnames';
import { __ } from '@wordpress/i18n';

export type PlaygroundDemoProps = Attributes & {
showAddNewFile: boolean;
Expand Down Expand Up @@ -80,7 +81,7 @@ export default function PlaygroundPreview({
logInUser,
createNewPost,
createNewPostType = 'post',
createNewPostTitle = 'New post',
createNewPostTitle = __('New post', 'interactive-code-block'),
createNewPostContent = '',
redirectToPost,
redirectToPostType = 'front',
Expand Down Expand Up @@ -187,7 +188,9 @@ export default function PlaygroundPreview({
if (finalBlueprint) {
configuration['blueprint'] = finalBlueprint;
}
console.log('Initializing Playground');
console.log(
__('Initializing Playground', 'interactive-code-block')
);
const client = await startPlaygroundWeb(configuration);

await client.isReady();
Expand Down Expand Up @@ -307,9 +310,11 @@ export default function PlaygroundPreview({
'is-half-width': codeEditorSideBySide,
});

const iframeCreationWarning =
const iframeCreationWarning = __(
'This button creates an iframe containing a full WordPress website ' +
'which may be a challenge for screen readers.';
'which may be a challenge for screen readers.',
'interactive-code-block'
);

return (
<>
Expand Down Expand Up @@ -359,7 +364,10 @@ export default function PlaygroundPreview({
</Button>
{isNewFileModalOpen && (
<FileNameModal
title="Create new file"
title={__(
'Create new file',
'interactive-code-block'
)}
onRequestClose={() =>
setNewFileModalOpen(false)
}
Expand Down Expand Up @@ -404,7 +412,11 @@ export default function PlaygroundPreview({
}}
className="wordpress-playground-block-button button-non-destructive"
>
<Icon icon={edit} /> Edit file name
<Icon icon={edit} />{' '}
{__(
'Edit file name',
'interactive-code-block'
)}
</button>
)}
{!isErrorLogFile(activeFile) &&
Expand All @@ -422,12 +434,18 @@ export default function PlaygroundPreview({
<Icon
icon={cancelCircleFilled}
/>{' '}
Remove file
{__(
'Remove file',
'interactive-code-block'
)}
</button>
)}
{isEditFileNameModalOpen && (
<FileNameModal
title="Edit file name"
title={__(
'Edit file name',
'interactive-code-block'
)}
initialFilename={
files[activeFileIndex].name
}
Expand Down Expand Up @@ -461,7 +479,7 @@ export default function PlaygroundPreview({
: undefined
}
>
Run
{__('Run', 'interactive-code-block')}
</Button>
</div>
</div>
Expand All @@ -474,13 +492,19 @@ export default function PlaygroundPreview({
onClick={() => setLivePreviewActivated(true)}
aria-description={iframeCreationWarning}
>
Activate Live Preview
{__(
'Activate Live Preview',
'interactive-code-block'
)}
</Button>
</div>
)}
{isLivePreviewActivated && (
<iframe
aria-label="Live Preview in WordPress Playground"
aria-label={__(
'Live Preview in WordPress Playground',
'interactive-code-block'
)}
key="playground-iframe"
ref={iframeRef}
className="playground-iframe"
Expand All @@ -493,10 +517,12 @@ export default function PlaygroundPreview({
className="demo-footer__link"
target="_blank"
>
<span className="demo-footer__powered">Powered by</span>
<span className="demo-footer__powered">
{__('Powered by', 'interactive-code-block')}
</span>
<Icon className="demo-footer__icon" icon={wordpress} />
<span className="demo-footer__link-text">
WordPress Playground
{__('WordPress Playground', 'interactive-code-block')}
</span>
</a>
</footer>
Expand Down
Loading
Loading