I'm currently working at ePark - A parking app in Sweden, Poland and Norway.
Formerly co-founder & Tech Lead/Architect at Heap Carsharing - A peer-to-peer carsharing startup in Sweden 🚗
I am sometimes available for freelance work.
Automatically update the language files for core, plugins and themes after running install|update in composer.
I'm currently working at ePark - A parking app in Sweden, Poland and Norway.
Formerly co-founder & Tech Lead/Architect at Heap Carsharing - A peer-to-peer carsharing startup in Sweden 🚗
I am sometimes available for freelance work.
Composer docs: https://getcomposer.org/apidoc/1.3.0/Composer/Package/Locker.html#method_setLockData
This should then be used when running composer install
.
post-package-install
and post-package-update
will only be executed after package installation/update (see https://getcomposer.org/doc/articles/scripts.md#package-events). But language packs change independently of the package they belong to. At any time, translations can be updated/changed in GlotPress. AFAIK these language updates won't get installed with the currently used hooks.
So the more appropriate hooks probably should be post-install-cmd
and post-update-cmd
(see https://getcomposer.org/doc/articles/scripts.md#command-events) even if this causes the script to run more frequently.
When using the mentioned hooks though, I get the following fatal error:
> AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::install_t10ns
Fatal error: Uncaught TypeError: Argument 1 passed to AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::install_t10ns()
must be an instance of Composer\Installer\PackageEvent, instance of Composer\Script\Event given,
called in phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php on line 292
and defined in /path/to/project/vendor/pelmered/composer-plugin-language-update/src/PostUpdateLanguageUpdate.php:42
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(292):
AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::install_t10ns(Object(Composer\Script\Event))
#1 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(215):
Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('AngryCreative\\W...', 'install_t10ns', Object(Composer\Script\Event))
#2 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(81): Composer\EventDispatcher\EventDispatcher->doDispatch(Object in
/path/to/project/vendor/pelmered/composer-plugin-language-update/src/PostUpdateLanguageUpdate.php on line 42
Failed to update packages for ./composer.json.
What do you think? Should the hooks be changed?
Any feedback appreciated! Thanks!
scripts
property of composer.json
:
"scripts": {
"post-package-install": [
"AngryCreative\\WPLanguageUpdater\\PostUpdateLanguageUpdate::install_t10ns"
],
"post-package-update": [
"AngryCreative\\WPLanguageUpdater\\PostUpdateLanguageUpdate::update_t10ns"
]
}
When running composer update
I get the following fatal error:
> AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::update_t10ns
Fatal error: Uncaught Error: Call to undefined method AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::locate_wp_content()
in /Applications/AMPPS/www/mtrix.test/vendor/pelmered/composer-plugin-language-update/src/PostUpdateLanguageUpdate.php:110
Stack trace:
#0 /Applications/AMPPS/www/mtrix.test/vendor/pelmered/composer-plugin-language-update/src/PostUpdateLanguageUpdate.php(75):
AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::set_config()
#1 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(292):
AngryCreative\WPLanguageUpdater\PostUpdateLanguageUpdate::update_t10ns(Object(Composer\Installer\PackageEvent))
#2 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(215):
Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('AngryCreative\\W...', 'update_t10ns', Object(Composer\Installer\PackageEvent))
#3 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(116):
Composer\EventDispatcher\EventDispatcher->doDispatc in /Applications/AMPPS/www/mtrix.test/vendor/pelmered/composer-plugin-language-update/src/PostUpdateLanguageUpdate.php on line 110
Failed to update packages for ./composer.json.
I'm using https://github.com/dnaber-de/wpstarter-boilerplate if that's relevant.
Related: #2.
This package manages translations for not only plugins so we need a new name the better reflect this functionality.
Also the namespace should be changed.
install_t10ns()
and update_t10ns()
have almost identical function bodies. IMO they should be merged in one method (with a conditional check what hook the method is currently added to).
This would allow users to add the same function call to both the install and update hook, or use a referenced script like it's used in WP Starter's composer.json
.
Recently, we had a lengthy internal discussion about a Composer based solution to get translations. The main reservation against this package (beside the fact that the code isn't really "clean") was that it uses Guzzle to download the translations:
The chances you get a dependencies conflict for something that is not even needed in production is very high. Ideally, building scripts should have no dependencies at all, but a such popular and big dependency like Guzzle is clearly a non-best practice.
― @gmazzap
An appropriate alternative is Composer's RemoteFilesystem
class or even just file_get_contents()
as in @bjornjohansen's wplang.
Maybe you want to follow wecodemore/wpstarter#44, especially wecodemore/wpstarter#44 (comment) as this covers all requirements of a Composer based translation download in a modern WordPress stack.
Hi,
I am using bedrock wordpress and plugin and theme language files are downloaded, but no wordpress core language files.
I was looking into your code and found this:
case 'package':
if ( 'johnpbloch/wordpress' === $package->getName() ) {
$this->package_type = 'core';
$this->slug = 'wordpress-core';
break;
}
I am using root/wordpress package for core, so looks like this would be a problem. Aren't there other way of determining core package except name?
Michal
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.