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

Locales are not found if set in env.php and not in core_config_table #13

Open
MaximGns opened this issue Apr 9, 2024 · 0 comments
Open

Comments

@MaximGns
Copy link

MaximGns commented Apr 9, 2024

Used following plugin to fix

<?php

declare(strict_types=1);

namespace Vendor\PhproTranslations\Plugin;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\StoreManager;
use Phpro\Translations\Model\Translation\Source\Locales as SourceLocales;

class Locales
{
    private const XML_PATH_LOCALE = 'general/locale/code';

    public function __construct(
        private readonly ScopeConfigInterface $scopeConfig,
        private readonly StoreManager $storeManager,
    ) {
    }

    /**
     * @param SourceLocales $subject
     * @param callable $proceed
     * @return array
     */
    public function aroundToOptionArray(SourceLocales $subject, callable $proceed): array
    {
        $stores = $this->storeManager->getStores();

        $result = [];
        foreach ($stores as $store) {
            $locale = $this->scopeConfig->getValue(self::XML_PATH_LOCALE, 'stores', $store->getId());
            $result[] = ['value' => $locale, 'label' => $store->getName()];
        }

        return $result;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant