roots / acorn

Laravel components for WordPress plugins and themes
https://roots.io/acorn/
MIT License
788 stars 90 forks source link

Support l10n in config files #300

Open ouun opened 1 year ago

ouun commented 1 year ago

Version

3.2.0

What did you expect to happen?

Using __() in config files registers the strings for gettext and $this->app->config->get() gets the config with the translated strings.

What actually happens?

$this->app->config->get() / config() gets the original strings and not the translation. Also please see this issue for Poet.

Steps to reproduce

Add a string with __() to any config file, translate it and get the config with config().

System info

No response

Log output

No response

Please confirm this isn't a support request.

Yes

QWp6t commented 1 year ago

Is this the result of a cached config?

ouun commented 1 year ago

@QWp6t cached and not cached.

oxyc commented 1 year ago

I used this on a multisite with acorn v2 and parent/child themes that had similar issues, maybe it’s useful https://gist.github.com/oxyc/d5f62c41b6ed87f743d33c1b3c5a5c30

ouun commented 1 year ago

Hi @oxyc Thanks a lot but I am afraid I do not get the context. Can you please explain a bit which parts might be of help to solve what? Is this overwriting the Config getter? Thanks a lot

oxyc commented 8 months ago

So 6 months later I updated acorn :)

In functions.php I changed:

@@ -40,7 +40,12 @@ if (! function_exists('\Roots\bootloader')) {
     );
 }

-\Roots\bootloader()->boot();
+$bootloader = \Roots\bootloader();
+$bootloader->getApplication()->bind(
+    \Roots\Acorn\Bootstrap\LoadConfiguration::class,
+    \App\Bootstrap\LoadConfiguration::class
+);
+$bootloader->boot();

 /*

Add added this to app/Boostrap/LoadConfiguration.php:

<?php

namespace App\Bootstrap;

use Illuminate\Contracts\Foundation\Application;
use Roots\Acorn\Bootstrap\LoadConfiguration as AcornLoadConfiguration;

class LoadConfiguration extends AcornLoadConfiguration
{
    /**
     * {@inheritdoc}
     */
    public function bootstrap(Application $app)
    {
        parent::bootstrap($app);

        // When `wp acorn optimize` runs it will create a cached config.php file
        // with pre-determined values at build times. This causes issues with
        // multisite since the config.php file uses get_theme_file_path() which
        // needs to be dynamically evaluated per site.
        // Here we override the cached config by re-evaluating the config files.
        $this->loadConfigurationFiles($app, $app->make('config'));
    }
}

The context for this was parent/child theme having cached theme paths but same should apply to l10n.

slackday commented 7 months ago

Any update on fixing this? I get translations to work as normal in WordPress but then suddenly they stop working. I try some combination of wp acorn optimize wp acorn optimize:clear yarn translate yarn translate:compile and it starts working again to stop working again later on. Not sure what's wrong.

retlehs commented 7 months ago

All the updates so far are in this issue — there has not yet been a PR submitted to address this in Acorn

Did you try the solution from the comment above you?

slackday commented 6 months ago

Sorry if I hijacked the issue. I tried the solutions but they did not work for me. My problem seems to be with log1x/poet package. This comment helped me https://github.com/Log1x/poet/issues/46#issuecomment-1839387026