Skip to content

Commit

Permalink
Internationalize #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 11, 2021
1 parent 4836b7a commit bc5cbeb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 70 deletions.
6 changes: 3 additions & 3 deletions includes/oik-magnetic-poetry.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @copyright (C) Copyright Bobbing Wide 2019
* @copyright (C) Copyright Bobbing Wide 2019, 2021
*/

/**
Expand All @@ -18,7 +18,7 @@ function oikmp_poetry( $attributes, $content ) {
$content = hello_dolly_get_lyric();
oikmp_poetry_content( $content );
} else {
oikmp_poetry_content( "Code is Poetry" );
oikmp_poetry_content( __( "Code is Poetry", 'oik-magnetic-poetry' ) );
}

$html = bw_ret();
Expand Down Expand Up @@ -85,4 +85,4 @@ function oik_magnetic_poetry_example() {
//bw_flush();
return bw_ret();

}
}
44 changes: 28 additions & 16 deletions oik-magnetic-poetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Magnetic poetry block
* Author: Herb Miller
* Author URI: https://herbmiller.me/author/herb
* Version: 0.2.1
* Version: 0.2.2
* License: GPL3+
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*
Expand Down Expand Up @@ -43,23 +43,35 @@ function oik_magnetic_poetry_loaded() {
* Registers the Magnetic Poetry block.
*/
function oikmp_register_dynamic_blocks() {
$library_file = oik_require_lib( 'oik-blocks' );
/*
oik\oik_blocks\oik_blocks_register_editor_scripts( 'oik-magnetic-poetry', 'oik-magnetic-poetry');
oik\oik_blocks\oik_blocks_register_block_styles( 'oik-magnetic-poetry' );
register_block_type( 'oik-mp/magnetic-poetry',
[ 'render_callback' => 'oikmp_dynamic_block_poetry'
, 'editor_script' => 'oik-magnetic-poetry-blocks-js'
, 'editor_style' => 'oik-magnetic-poetry-blocks-css'
, 'style' => 'oik-magnetic-poetry-blocks-css'
, 'attributes' => [
'content' => [ 'type' => 'string']
]
] );
*/
$args = [ 'render_callback' => 'oikmp_dynamic_block_poetry'];
$registered = register_block_type_from_metadata( __DIR__ . '/src/oik-magnetic-poetry', $args );
//bw_trace2( $registered, "registered", false );
/**
* Localise the script by loading the required strings for the build/index.js file
* from the locale specific .json file in the languages folder.
*/
$ok = wp_set_script_translations( 'oik-mp-magnetic-poetry-editor-script', 'oik-magnetic-poetry' , __DIR__ .'/languages' );
add_filter( 'load_script_textdomain_relative_path', 'oikmp_load_script_textdomain_relative_path', 10, 2);
}

/**
* Filters $relative so that md5's match what's expected.
*
* Depending on how it was built the `build/index.js` may be preceded by `./` or `src/block-name/../../`.
* In either of these situations we want the $relative value to be returned as `build/index.js`.
* This then produces the correct md5 value and the .json file is found.
*
* @param $relative
* @param $src
*
* @return mixed
*/
function oikmp_load_script_textdomain_relative_path( $relative, $src ) {
if ( false !== strrpos( $relative, './build/index.js' )) {
$relative = 'build/index.js';
}
//bw_trace2( $relative, "relative");
return $relative;
}

/**
Expand Down Expand Up @@ -94,7 +106,6 @@ function oikmp_server_side_wrapper( $attributes, $html ) {
return $html;
}


/**
* Implements 'plugins_loaded' action for oik-magnetic-poetry.
*
Expand All @@ -104,6 +115,7 @@ function oik_magnetic_poetry_plugins_loaded() {
oik_magnetic_poetry_boot_libs();
oik_require_lib( "bwtrace" );
oik_require_lib( "bobbfunc" );
bw_load_plugin_textdomain( "oik-magnetic-poetry");
}

/**
Expand Down
58 changes: 7 additions & 51 deletions src/oik-magnetic-poetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
*
* Uses logic from oik-magnetic-poetry plugin
*
* @copyright (C) Copyright Bobbing Wide 2019, 2020
* @copyright (C) Copyright Bobbing Wide 2019, 2020, 2021
* @author Herb Miller @bobbingwide
*/
import './style.scss';
//import './editor.scss';


import { __ } from '@wordpress/i18n';
import classnames from 'classnames';

// Get registerBlockType from wp.blocks
import { registerBlockType, createBlock } from '@wordpress/blocks';
import {AlignmentControl, BlockControls, InspectorControls, useBlockProps, PlainText} from '@wordpress/block-editor';
import ServerSideRender from '@wordpress/server-side-render';
Expand All @@ -27,13 +23,10 @@ import {
import { Fragment} from '@wordpress/element';
import { map, partial } from 'lodash';

import metadata from './block.json';

/**
* Register the WordPress block
*/

export default registerBlockType( metadata,
export default registerBlockType( 'oik-mp/magnetic-poetry',
{
example: {
},
Expand Down Expand Up @@ -71,7 +64,6 @@ export default registerBlockType( metadata,
]
},


edit: props => {

const { textAlign, label } = props.attributes;
Expand All @@ -86,52 +78,24 @@ export default registerBlockType( metadata,
props.setAttributes( { content: value } );
};

/**
* Attempt a generic function to apply a change
* using the partial technique
*
* key needs to be in [] otherwise it becomes a literal
*
*/
//onChange={ partial( handleChange, 'someKey' ) }

function onChangeAttr( key, value ) {
//var nextAttributes = {};
//nextAttributes[ key ] = value;
//setAttributes( nextAttributes );
props.setAttributes( { [key] : value } );
};

const isSelected = props.isSelected;




return (
<Fragment>
<BlockControls group="block">
<BlockControls>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
props.setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<InspectorControls >
<PanelBody>

<PanelRow>

</PanelRow>

</PanelBody>

</InspectorControls>
{!isSelected &&
<div { ...blockProps}>
<ServerSideRender
<ServerSideRender
block="oik-mp/magnetic-poetry" attributes={props.attributes}
/>
/>
</div>
}

Expand All @@ -140,21 +104,13 @@ export default registerBlockType( metadata,
<div { ...blockProps}>
<PlainText
value={props.attributes.content}
placeholder={__('Write poetry')}
placeholder={__('Write poetry','oik-magnetic-poetry')}
onChange={onChangeContent}
/>
</div>
}


</Fragment>

);
},


save() {
return null;
},
}
},
);

0 comments on commit bc5cbeb

Please sign in to comment.