getLocales example

/** * Fetches known server locales. Returns a struct in server format containing * info about the current user's locale. * * @return LocaleStruct|null Information about the current locale */
    private function getCurrentLocale(): ?LocaleStruct
    {
        if (empty(self::$locales)) {
            $accountManagerService = $this->container->get('shopware_plugininstaller.account_manager_service');

            foreach ($accountManagerService->getLocales() as $serverLocale) {
                self::$locales[$serverLocale->getName()] = $serverLocale;
            }
        }

        $localeCode = $this->container->get('auth')->getIdentity()->locale->getLocale();

        if (\array_key_exists($localeCode, self::$locales)) {
            return self::$locales[$localeCode];
        }

        // Fallback to english locale when available


    /** * Gets the available backend locales excluding the current one * * @return void */
    public function getAlternativeLocalesAction()
    {
        $targetLocale = Shopware()->Container()->get('auth')->getIdentity()->locale;

        $locales = Shopware()->Plugins()->Backend()->Auth()->getLocales();

        if (($key = array_search($targetLocale->getId()$locales)) !== false) {
            unset($locales[$key]);
        }

        $locales = Shopware()->Db()->quote($locales);
        $sql = 'SELECT id, locale FROM s_core_locales WHERE id IN (' . $locales . ')';
        $locales = Shopware()->Db()->fetchPairs($sql);

        $data = [];
        foreach ($locales as $id => $locale) {
            
foreach ($catalogue->all() as $domain => $messages) {
            $createdIds = $this->createAssets(array_keys($messages)$domain);
            if ($createdIds) {
                $this->tagsAssets($createdIds$domain);
            }
        }

        foreach ($translatorBag->getCatalogues() as $catalogue) {
            $locale = $catalogue->getLocale();

            if (!\in_array($locale$this->getLocales())) {
                $this->createLocale($locale);
            }

            foreach ($catalogue->all() as $domain => $messages) {
                $keysIdsMap = [];

                foreach ($this->getAssetsIds($domain) as $id) {
                    $keysIdsMap[$this->retrieveKeyFromId($id$domain)] = $id;
                }

                $assets = [];
                
/** * Gets the available backend locales and returns them in an ExtJS * friendly format * * Note that this function returns sample data to build up the module. * * @return void */
    public function getLocalesAction()
    {
        $current = Shopware()->Container()->get('locale');
        $locales = $this->getPlugin()->getLocales();
        $locales = Shopware()->Db()->quote($locales);
        $sql = 'SELECT id, locale FROM s_core_locales WHERE id IN (' . $locales . ')';
        $locales = Shopware()->Db()->fetchPairs($sql);

        $data = [];
        foreach ($locales as $id => $locale) {
            list($l$t) = explode('_', $locale);
            $l = $current::getTranslation($l, 'language', $current);
            $t = $current::getTranslation($t, 'territory', $current);
            $data[] = [
                'id' => $id,
                


    protected function tearDown(): void
    {
        \Locale::setDefault($this->defaultLocale);
    }

    public function provideLocales()
    {
        return array_map(
            fn ($locale) => [$locale],
            $this->getLocales()
        );
    }

    public function provideLocaleAliases()
    {
        return array_map(
            fn ($alias$ofLocale) => [$alias$ofLocale],
            array_keys($this->getLocaleAliases()),
            $this->getLocaleAliases()
        );
    }

    
use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Locales;

/** * @group intl-data */
class LocalesTest extends ResourceBundleTestCase
{
    public function testGetLocales()
    {
        $this->assertSame($this->getLocales(), Locales::getLocales());
    }

    public function testGetAliases()
    {
        $this->assertSame($this->getLocaleAliases(), Locales::getAliases());
    }

    /** * @dataProvider provideLocales */
    public function testGetNames($displayLocale)
    {
Smarty::PLUGIN_FUNCTION,
            'acl_is_allowed',
            [$this, 'isAllowed']
        );
    }

    /** * @return string */
    public function getDefaultLocale()
    {
        $backendLocales = $this->getLocales();
        $browserLocales = array_keys(Zend_Locale::getBrowser());

        if (!empty($browserLocales)) {
            $quotedBackendLocale = Shopware()->Db()->quote($backendLocales);
            $orderIndex = 1;
            $orderCriteria = '';
            foreach ($browserLocales as $browserLocale) {
                $orderCriteria .= 'WHEN ' . Shopware()->Db()->quote($browserLocale) . ' THEN ' . $orderIndex . ' ';
                ++$orderIndex;
            }
            $orderCriteria .= 'ELSE ' . $orderIndex . ' END ';

            
Home | Imprint | This part of the site doesn't use cookies.