Skip to content
Snippets Groups Projects
Verified Commit ba3d252f authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

fix: i18n file path

parent e791b5ea
Branches v0.10
Tags 0.10.6
1 merge request!5feat: remove compilation command
Pipeline #461793 passed with warnings
# wp-init changelog # wp-init changelog
## [0.10.6] - 2025-01-10
### Fixed
- Fixed path for loading plugin translations.
### Changed
- Improved _development_ environment detection. Now, in addition to previous methods, adding `dev` suffix to plugin version enabled development environment (no container compilation).
## [0.10.5] - 2025-01-09 ## [0.10.5] - 2025-01-09
### Fixed ### Fixed
- Fixed condition checking if current environment is development, causing container to always use live version. - Fixed condition checking if current environment is development, causing container to always use live version.
......
...@@ -22,10 +22,18 @@ class I18n implements Hookable { ...@@ -22,10 +22,18 @@ class I18n implements Hookable {
} }
public function __invoke(): void { public function __invoke(): void {
$relative_path = str_replace(
WP_PLUGIN_DIR . '/',
'',
$this->plugin->get_path(
$this->plugin->header()->get( 'DomainPath' )
)
);
\load_plugin_textdomain( \load_plugin_textdomain(
$this->plugin->get_slug(), $this->plugin->get_slug(),
false, false,
$this->plugin->header()->get( 'DomainPath' ) $relative_path
); );
} }
} }
...@@ -79,7 +79,7 @@ final class Kernel { ...@@ -79,7 +79,7 @@ final class Kernel {
$container->set( Plugin::class, $plugin ); $container->set( Plugin::class, $plugin );
$container->set( Configuration::class, $this->config ); $container->set( Configuration::class, $this->config );
$this->prepare_driver( $container )->register_hooks(); $this->prepare_driver( $container, $plugin )->register_hooks();
} }
private function get_cache_path( string $path = '' ): string { private function get_cache_path( string $path = '' ): string {
...@@ -88,14 +88,19 @@ final class Kernel { ...@@ -88,14 +88,19 @@ final class Kernel {
); );
} }
/**
* Container name in scheme: `<slug>_<version>_container`.
*
* Container is compiled in client environment, so in order to allow graceful upgrade, include version name to the container. Compiled container class is also autoloaded, so it is necessary that name is unique enough to avoid clash with other plugins.
*/
private function get_container_name( Plugin $plugin ): string { private function get_container_name( Plugin $plugin ): string {
return preg_replace( '/[^\w_]/', '_', implode("_", [ $plugin->get_slug(), $plugin->get_version(), 'container' ]) ); return preg_replace( '/[^\w_]/', '_', implode( '_', [ $plugin->get_slug(), $plugin->get_version(), 'container' ] ) );
} }
private function initialize_container( Plugin $plugin, bool $use_cache = true ): Container { private function initialize_container( Plugin $plugin, bool $use_cache = true ): Container {
$original_builder = new DiBuilder(); $original_builder = new DiBuilder();
if ( $this->is_prod() && $use_cache ) { if ( $this->is_prod( $plugin ) && $use_cache ) {
$original_builder->enableCompilation( $original_builder->enableCompilation(
$this->get_cache_path(), $this->get_cache_path(),
$this->get_container_name( $plugin ) $this->get_container_name( $plugin )
...@@ -124,7 +129,7 @@ final class Kernel { ...@@ -124,7 +129,7 @@ final class Kernel {
} }
} }
private function prepare_driver( ContainerInterface $container ): HookDriver { private function prepare_driver( ContainerInterface $container, Plugin $plugin ): HookDriver {
$loader = new CompositeBindingLoader(); $loader = new CompositeBindingLoader();
foreach ( $this->extensions as $extension ) { foreach ( $this->extensions as $extension ) {
$loader->add( $extension->bindings( $container ) ); $loader->add( $extension->bindings( $container ) );
...@@ -134,7 +139,7 @@ final class Kernel { ...@@ -134,7 +139,7 @@ final class Kernel {
new ClusteredLoader( $loader ) new ClusteredLoader( $loader )
); );
if ( $this->is_dev() ) { if ( $this->is_dev( $plugin ) ) {
$loader = new DebugBindingLoader( $loader ); $loader = new DebugBindingLoader( $loader );
} }
...@@ -156,11 +161,11 @@ final class Kernel { ...@@ -156,11 +161,11 @@ final class Kernel {
return $driver; return $driver;
} }
private function is_dev(): bool { private function is_dev( Plugin $plugin ): bool {
return $this->config->get( 'debug', false ) || wp_get_environment_type() === 'development'; return $this->config->get( 'debug', false ) || wp_get_environment_type() === 'development' || str_contains( $plugin->get_version(), 'dev' );
} }
private function is_prod(): bool { private function is_prod( Plugin $plugin ): bool {
return $this->is_dev() === false; return $this->is_dev( $plugin ) === false;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment