Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support l10n in config files #300

Open
ouun opened this issue Jul 25, 2023 · 8 comments
Open

Support l10n in config files #300

ouun opened this issue Jul 25, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@ouun
Copy link
Sponsor Contributor

ouun commented Jul 25, 2023

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

@ouun ouun added the bug Something isn't working label Jul 25, 2023
@QWp6t
Copy link
Sponsor Member

QWp6t commented Jul 25, 2023

Is this the result of a cached config?

@ouun
Copy link
Sponsor Contributor Author

ouun commented Jul 25, 2023

@QWp6t cached and not cached.

@oxyc
Copy link
Contributor

oxyc commented Jul 26, 2023

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
Copy link
Sponsor Contributor Author

ouun commented Jul 29, 2023

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
Copy link
Contributor

oxyc commented Jan 17, 2024

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
Copy link

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
Copy link
Sponsor Member

retlehs commented Feb 21, 2024

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
Copy link

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 Log1x/poet#46 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants