getLocale example

$result->addSuccess($orderId$doc);

                        continue;
                    }

                    $deliveries = null;
                    if ($order->getDeliveries()) {
                        $deliveries = $order->getDeliveries()->first();
                    }

                    /** @var LocaleEntity $locale */
                    $locale = $order->getLanguage()->getLocale();

                    $html = $this->documentTemplateRenderer->render(
                        $template,
                        [
                            'order' => $order,
                            'orderDelivery' => $deliveries,
                            'config' => $config,
                            'rootDir' => $this->rootDir,
                            'context' => $context,
                        ],
                        $context,
                        


        return $this->debug;
    }

    public function getLocale(): string
    {
        if (!isset($this->localeSwitcher)) {
            throw new \RuntimeException('The "app.locale" variable is not available.');
        }

        return $this->localeSwitcher->getLocale();
    }

    /** * Returns some or all the existing flash messages: * * getFlashes() returns all the flash messages * * getFlashes('notice') returns a simple array with flash messages of that type * * getFlashes(['notice', 'error']) returns a nested array of type => messages. */
    public function getFlashes(string|array $types = null): array
    {
        try {
            

class PoFileDumper extends FileDumper
{
    public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string
    {
        $output = 'msgid ""'."\n";
        $output .= 'msgstr ""'."\n";
        $output .= '"Content-Type: text/plain; charset=UTF-8\n"'."\n";
        $output .= '"Content-Transfer-Encoding: 8bit\n"'."\n";
        $output .= '"Language: '.$messages->getLocale().'\n"'."\n";
        $output .= "\n";

        $newLine = false;
        foreach ($messages->all($domain) as $source => $target) {
            if ($newLine) {
                $output .= "\n";
            } else {
                $newLine = true;
            }
            $metadata = $messages->getMetadata($source$domain);

            

        $messages = $this->sanitizeCollectedMessages($this->translator->getCollectedMessages());

        $this->data += $this->computeCount($messages);
        $this->data['messages'] = $messages;

        $this->data = $this->cloneVar($this->data);
    }

    public function collect(Request $request, Response $response, \Throwable $exception = null): void
    {
        $this->data['locale'] = $this->translator->getLocale();
        $this->data['fallback_locales'] = $this->translator->getFallbackLocales();
    }

    public function reset(): void
    {
        $this->data = [];
    }

    public function getMessages(): array|Data
    {
        return $this->data['messages'] ?? [];
    }
static::assertSame(
            $request,
            $this->getContainer()->get(RequestStack::class)->pop()
        );
    }

    public function testSymfonyDefaultTranslationFallback(): void
    {
        $this->translator->reset();
        $catalogue = $this->translator->getCatalogue('en');
        static::assertInstanceOf(MessageCatalogueInterface::class$catalogue->getFallbackCatalogue());
        static::assertEquals('en_GB', $catalogue->getFallbackCatalogue()->getLocale());

        $this->translator->reset();
        $catalogue = $this->translator->getCatalogue('en_GB');
        static::assertInstanceOf(MessageCatalogueInterface::class$catalogue->getFallbackCatalogue());
        static::assertEquals('en_001', $catalogue->getFallbackCatalogue()->getLocale());

        $this->translator->reset();
        $catalogue = $this->translator->getCatalogue('en-GB');
        $fallback = $catalogue->getFallbackCatalogue();
        static::assertInstanceOf(MessageCatalogueInterface::class$fallback);
        static::assertEquals('en', $fallback->getLocale());
        
$locale = null;

        // Determine how to query the current language         if ($container->initialized('auth') && $container->get('auth')->hasIdentity()) {
            $identity = $container->get('auth')->getIdentity();
            if (isset($identity->locale)) {
                $locale = $identity->locale;
            } elseif (isset($identity->localeID)) {
                $locale = $container->get(ModelManager::class)->getRepository(ShopLocale::class)->find($identity->localeID);
            }
        } elseif ($container->initialized('shop')) {
            $locale = $container->get('shop')->getLocale();
        }

        if ($locale) {
            $this->localeId = $locale->getId();
        }

        // Determine fallback language         $this->fallbackLocaleId = $this->getFallbackLocaleId($this->localeId);
    }

    /** * Filter translation data for saving. * * @param string $type * @param int|null $key * * @return string */
$view->assign('baseUrl', $request->getBaseUrl() . $request->getPathInfo());

        $shop = Shopware()->Shop();
        $view->assign('Controller', $args->getSubject()->Request()->getControllerName());

        $view->assign('sBasketQuantity', $view->getAssign('sBasketQuantity') ?: 0);
        $view->assign('sBasketAmount', $view->getAssign('sBasketAmount') ?: 0);
        $view->assign('sNotesQuantity', $view->getAssign('sNotesQuantity') ?: 0);
        $view->assign('sUserLoggedIn', $view->getAssign('sUserLoggedIn') ?: false);

        $view->assign('Shop', $shop);
        if (!$shop->getLocale() instanceof ShopLocale) {
            throw new RuntimeException('Shop does not have a locale set');
        }
        $view->assign('Locale', $shop->getLocale()->getLocale());

        $view->assign('sCategoryStart', $shop->getCategory()->getId());
        $view->assign('sCategoryCurrent', $this->getCategoryCurrent($view->getAssign('sCategoryStart')));
        $view->assign('sCategories', $this->getCategories($view->getAssign('sCategoryCurrent')));
        $view->assign('sMainCategories', $view->getAssign('sCategories'));
        $view->assign('sOutputNet', Shopware()->Session()->get('sOutputNet'));

        $activePage = $view->getAssign('sCustomPage')['id'] ?? null;
        
/** * Switch to a new locale, execute a callback, then switch back to the original. * * @template T * * @param callable(string $locale):T $callback * * @return T */
    public function runWithLocale(string $locale, callable $callback): mixed
    {
        $original = $this->getLocale();
        $this->setLocale($locale);

        try {
            return $callback($locale);
        } finally {
            $this->setLocale($original);
        }
    }

    public function reset(): void
    {
        
use Symfony\Component\Translation\Loader\JsonFileLoader;

class JsonFileLoaderTest extends TestCase
{
    public function testLoad()
    {
        $loader = new JsonFileLoader();
        $resource = __DIR__.'/../fixtures/resources.json';
        $catalogue = $loader->load($resource, 'en', 'domain1');

        $this->assertEquals(['foo' => 'bar']$catalogue->all('domain1'));
        $this->assertEquals('en', $catalogue->getLocale());
        $this->assertEquals([new FileResource($resource)]$catalogue->getResources());
    }

    public function testLoadDoesNothingIfEmpty()
    {
        $loader = new JsonFileLoader();
        $resource = __DIR__.'/../fixtures/empty.json';
        $catalogue = $loader->load($resource, 'en', 'domain1');

        $this->assertEquals([]$catalogue->all('domain1'));
        $this->assertEquals('en', $catalogue->getLocale());
        

    public function checkInstalledPluginsAvailableForNewVersion($version)
    {
        $service = $this->container->get(PluginStoreService::class);
        $installedPlugins = $this->getUserInstalledPlugins();
        $technicalNames = array_column($installedPlugins, 'name');
        $locale = $this->getLocale();

        $shopwareVersion = $this->container->getParameter('shopware.release.version');

        $request = new PluginsByTechnicalNameRequest($locale$shopwareVersion$technicalNames);
        $storePlugins = $service->getPlugins($request);

        $request = new PluginsByTechnicalNameRequest($locale$version$technicalNames);
        $updatesAvailable = $service->getPlugins($request);

        try {
            $results = [];
            
$subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
        }

        static $setSession;

        $setSession ??= \Closure::bind(static function D$subRequest$request) { $subRequest->session = $request->session; }, null, Request::class);
        $setSession($subRequest$request);

        if ($request->get('_format')) {
            $subRequest->attributes->set('_format', $request->get('_format'));
        }
        if ($request->getDefaultLocale() !== $request->getLocale()) {
            $subRequest->setLocale($request->getLocale());
        }
        if ($request->attributes->has('_stateless')) {
            $subRequest->attributes->set('_stateless', $request->attributes->get('_stateless'));
        }

        return $subRequest;
    }

    public function getName(): string
    {
        

            ->where('trans.form_id IS NULL')
            ->andWhere('form.name IS NOT NULL')
            ->setParameter('localeId', $locale->getId())
            ->execute();

        $missingFormLabels = $statement->fetchAll();

        $output->writeln('<info></info>');
        $output->writeln('<info>' . \count($missingFormLabels) . ' missing form labels detected</info>');
        if ($missingFormLabels) {
            $formLabelFilePath = $dir . 'formTranslations' . str_replace('_', '', $locale->getLocale()) . '.php';

            $output->writeln('<info>Writing to ' . $formLabelFilePath . '</info>');
            file_put_contents($formLabelFilePath, '<?php return ' . var_export($missingFormLabels, true) . ';');
        }
    }

    /** * Exports element labels from the database into a php file containing an array * * @param Locale $locale * @param string $dir * * @throws Exception */
if (!$event->isMainRequest()) {
            return;
        }

        $response = $event->getResponse();

        if (null === $response->getCharset()) {
            $response->setCharset($this->charset);
        }

        if ($this->addContentLanguageHeader && !$response->isInformational() && !$response->isEmpty() && !$response->headers->has('Content-Language')) {
            $response->headers->set('Content-Language', $event->getRequest()->getLocale());
        }

        if ($event->getRequest()->attributes->get('_vary_by_language')) {
            $response->setVary('Accept-Language', false);
        }

        $response->prepare($event->getRequest());
    }

    public static function getSubscribedEvents(): array
    {
        

        $translator = $this->getTranslator();
        $translator->setLocale('en_US_POSIX');

        $this->assertEquals($expected$translator->trans($id['%count%' => $number]));
    }

    public function testGetSetLocale()
    {
        $translator = $this->getTranslator();

        $this->assertEquals('en', $translator->getLocale());
    }

    /** * @requires extension intl */
    public function testGetLocaleReturnsDefaultLocaleIfNotSet()
    {
        $translator = $this->getTranslator();

        \Locale::setDefault('pt_BR');
        $this->assertEquals('pt_BR', $translator->getLocale());

        
$catalogue = $translatorBag->getCatalogues()[0];
        }

        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;
                }

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