Skip to content

Commit

Permalink
Issue #6 - support localization of block plugins using wp-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 4, 2020
1 parent 7db8551 commit cca4364
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 3,826 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# oik-i18n
![banner](https://raw.githubusercontent.com/bobbingwide/oik-i18n/master/assets/oik-i18n-banner-772x250.jpg)
* Contributors: bobbingwide
* Donate link: http://www.oik-plugins.com/oik/oik-donate/
* Tags: i18n, internationalization, localization, l10n, oik, bb_BB, bbboing
* Requires at least: 4.2
* Tested up to: 4.2.2
* Stable tag: 0.2
* Tested up to: 5.5.1
* Stable tag: 0.3.0
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -13,7 +14,6 @@ Internationalization for the oik suite of plugins

The base domain.pot file(s) are named to match the plugin. e.g. oik.pot, oik-i18n.pot


Translators build Machine Object (.mo) files where the filenames are expected to be in the form:


Expand Down Expand Up @@ -51,13 +51,7 @@ This is not really necessary, as the logic is currently intended for use in a 'b
1. Activate the oik-i18n plugin through the 'Plugins' menu in WordPress

## Frequently Asked Questions
# Where is the FAQ?
[oik FAQ](http://www.oik-plugins.com/oik/oik-faq)

# Is there a support forum?
Yes - please use the standard WordPress forum - http://wordpress.org/tags/oik?forum_id=10

# Who's written about i18n
# Who's written about i18n?

http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/

Expand All @@ -70,7 +64,7 @@ load_plugin_textdomain
load_theme_textdomain

# What is bb_BB?
We use bb_BB for a ficticious test language and country
We use bb_BB for a fictitious test language and country

bb = bbboing language - an automatic translation of the existing language with character movement and vowel replacement
BB = Bbboingland - the country where bbboing is spoken
Expand All @@ -93,6 +87,7 @@ bb_BB.php -

# What is makeoik.php?
makeoik.php is a PHP routine based on WordPress's makepot.php

It extends the list of functions that accept Internationalized strings
so that they can be found and included in the master .pot file for a plugin.
This .pot file is then passed to the translators ( including the automated routines )
Expand All @@ -104,9 +99,9 @@ for creation of the .po files... from which the .mo files are built.
# How do we run it?

Here we use oik-batch to invoke the l10n routine - localize a plugin
`
```
php c:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\oik-batch.php c:\apache\htdocs\wordpress\wp-content\plugins\oik-i18n\l10n.php %*
`
```
if you have a 'batch' file then you should be able to use

batch oik-i18n\l10n
Expand Down Expand Up @@ -158,13 +153,22 @@ Yes - see above
1. oik-i18n in action

## Upgrade Notice
# 0.3.0
Now supports plugins which deliver blocks built with wp-scripts

# 0.2
* Still not for general release.

# 0.1
* Not for general release.

## Changelog
# 0.3.0
* Changed: Added support for Internationalization and localization of block plugins,https://github.com/bobbingwide/oik-i18n/issues/6
* Tested: With WordPress 5.5.1
* Tested: With PHP 7.4


# 0.2
* Updated l10n.php to create the bb_BB locale version as part of oik-zip.php
* Other changes will be discovered next time round
Expand All @@ -176,6 +180,6 @@ Yes - see above

## Further reading
If you want to read more about the oik plugins then please visit the
[oik plugin](http://www.oik-plugins.com/oik)
[oik plugin](https://www.oik-plugins.com/oik)
**"the oik plugin - for often included key-information"**

Binary file added assets/oik-i18n-banner-772x250.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/oik-i18n-icon-256x256.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions bb_BB.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ function bb_BB( $plugin ) {
$real_file = "$plugin.pot" ;
$outfile = "$plugin-bb_BB.po";
}

echo $real_file;


if ( is_file($outfile) ) {
unlink( $outfile );
Expand Down Expand Up @@ -383,13 +386,13 @@ function boing( $word ) {
case 3:
// Can't really do anything with this length word
// Convert all vowels to uppercase
// Convert a to decimal 132 hex 84 - which is „ - a umlaut
// Convert e to decimal 130 hex 82 - which is ‚ - e acute
// Convert i to decimal 140 hex 8C - which is Œ - i caret
// Convert o to decimal 149 hex 95 - which is • - o grave
// Convert u to decimal 129 hex 81 - which is  - u umlaut
// Convert a to decimal 132 hex 84 - which is - a umlaut
// Convert e to decimal 130 hex 82 - which is - e acute
// Convert i to decimal 140 hex 8C - which is - i caret
// Convert o to decimal 149 hex 95 - which is - o grave
// Convert u to decimal 129 hex 81 - which is - u umlaut
$wrod = str_replace( array( "a", "e", "i", "o", "u" ), array( "A", "E", "I", "O", "U" ), $word );
// $wrod = str_replace( array( "a", "e", "i", "o", "u" ), array( "„", "‚", "Œ", "•", "" ), $word );
// $wrod = str_replace( array( "a", "e", "i", "o", "u" ), array( "", "", "", "", "" ), $word );

break;

Expand Down
97 changes: 92 additions & 5 deletions l10n.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // (C) Copyright Bobbing Wide 2013-2017
<?php // (C) Copyright Bobbing Wide 2013-2020

/**
* Syntax: oikwp l10n.php plugin langs
Expand Down Expand Up @@ -81,6 +81,7 @@ function l10n_run_l10n() {
} else {
$plugins = l10n_plugin_list();
echo "Processing plugin list";
echo "Not yet supported. Please specify the plugin to process.";
gobang();
}
$lang = oik_batch_query_value_from_argv( 2, "en_GB" );
Expand Down Expand Up @@ -166,7 +167,7 @@ function do_plugin( $plugin, $lang="en_GB" ) {
echo PHP_EOL;
//$res = do_makepot( $plugin );

$res = do_makeoik( $plugin );
$res = maybe_do_makeoik( $plugin );
//gob();
if ( $res ) {
$res = do_bb_BB( $plugin );
Expand All @@ -178,6 +179,47 @@ function do_plugin( $plugin, $lang="en_GB" ) {
}
}


/**
* Makeoik is required when we can't use makepot within npm.
*
* This is the case when the source files are in the same folder as the build files;
* as in the original versions of oik and oik-blocks.
*
* Until these plugins are converted to use wp-scripts then we won't have internationalised content in the editor.
* Newer plugins such as sb-children-block uses the modern method.
*
* node_modules | src | Process to use
* ------------ | ---- | ------------
* n | n | makeoik
* n | y | makeoik -
* y | n | makeoik - but JavaScipt blocks are not internationalised
* y | y | npm run makepot & npm run l10n & npm run makejson
*
* @param $plugin
* @return bool - always true?
*
*/
function maybe_do_makeoik( $plugin ) {
$node_modules = oik_path( 'node_modules', $plugin );
$src = oik_path( 'src', $plugin );
if ( file_exists( $node_modules ) && file_exists( $src ) ) {
echo "Not running makeoik - use npm run makepot";
echo "I assume you've already done that!";
echo PHP_EOL;
copytoworking( $plugin );
} else {
echo "Running makeoik";
echo PHP_EOL;
$res=do_makeoik( $plugin );
echo $res;
echo PHP_EOL;
copyfromworking( $plugin );
}
$res=true;
return $res;
}

/**
* Perform the first step - extract the translatable strings
*
Expand All @@ -189,7 +231,10 @@ function do_plugin( $plugin, $lang="en_GB" ) {
function do_makeoik( $plugin ) {
oik_require( "makeoik.php", "oik-i18n" );
$plugin_path = oik_path( null, $plugin );
echo "makeoik: " . $plugin_path;
echo PHP_EOL;
$makepot = new MakePOT;

$res = call_user_func( array( &$makepot, "wp_plugin" )
, $plugin_path
, null
Expand All @@ -199,6 +244,8 @@ function do_makeoik( $plugin ) {
if (false === $res) {
fwrite(STDERR, "Couldn't generate POT file!\n");
}
echo "result of makeoik: " . $res;
echo PHP_EOL;
return( $res );
}

Expand Down Expand Up @@ -287,9 +334,9 @@ function do_msgfmt( $plugin, $locale="bb_BB" ) {
function do_copytoplugin( $plugin, $locale="bb_BB" ) {
$source_dir = getcwd();
$target_dir = dirname( dirname( $source_dir) );
$target_dir .= "/$plugin/languages/";
$target_dir .= "/$plugin/languages";
oik_require( "admin/oik-relocate.inc" );
// Note: bw_mkdir expects a full file name
// Note: bw_mkdir expects a full file name but doesn't use the filename bit
bw_mkdir( "$target_dir/$plugin.pot" );

if ( $source_dir != $target_dir ) {
Expand All @@ -300,5 +347,45 @@ function do_copytoplugin( $plugin, $locale="bb_BB" ) {
copy( "$source_dir/$plugin-$locale.mo", "$target_dir/$plugin-$locale.mo" );
echo "Copied files from source: $source_dir" . PHP_EOL;
echo "Copied files to target: $target_dir" . PHP_EOL;
} else {
echo "Not copied from source to target" . PHP_EOL;
echo "Source: $source_dir" . PHP_EOL;
echo "Target: $target_dir" . PHP_EOL;
}
}
}

/**
* Copies the plugin.pot file from $plugin/languages to oik-i18n/working
*
* Note: The current working directory is expected to be oik-i18n/working
*
* @param $plugin
*/
function copytoworking( $plugin ) {
$target_dir = getcwd();
$source_dir = dirname( dirname( $target_dir) );
$source_dir .= "/$plugin/languages";
$result = copy( "$source_dir/$plugin.pot", "$target_dir/$plugin.pot");
echo "Copied $plugin.pot to working?";
echo $result ? "OK" : "Failed";
echo PHP_EOL;
}

/**
* Copies the plugin.pot file from oik-i18n/working to $plugin/languages
*
* Note: The current working directory is expected to be oik-i18n/working
*
* @param $plugin
*/
function copyfromworking( $plugin ) {
$source_dir = getcwd();
$target_dir = dirname( dirname( $source_dir) );
$target_dir .= "/$plugin/languages";
echo "Source dir: " . $source_dir;
echo "Target dir: " . $target_dir;
$result = copy( "$source_dir/$plugin.pot", "$target_dir/$plugin.pot");
echo "Copied $plugin.pot from working? ";
echo $result ? "OK" : "Failed";
echo PHP_EOL;
}
Binary file removed oik-bb_BB.mo
Binary file not shown.
Loading

0 comments on commit cca4364

Please sign in to comment.