Skip to content

Commit d1a12ed

Browse files
[Catalog] Require xx_XX locale format when syncing to Gally Fixes #32
1 parent 0215a07 commit d1a12ed

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
> The `nodejs` container automatically runs `yarn install && yarn build` and mounts the project into `/srv/sylius`.
111111
- Run `php bin/console doctrine:migrations:migrate` to update the database schema
112112
- Open Sylius Admin, head to Configuration > Gally and configure the Gally endpoint (URL, credentials), after that enable Gally on your channel (Configuration > Channel > Edit)
113+
> Every locale enabled on a Gally-active channel must use the full `xx_XX` format (e.g. `en_US`), not a bare
114+
> language code (e.g. `en`). Configure this in Sylius under Configuration > Locales.
113115
- Run this commands from your Sylius instance. This commands must be runned only once to synchronize the structure.
114116
```shell
115117
bin/console gally:structure:sync # Sync catalog et source field data with gally

src/Indexer/Provider/CatalogProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ public function buildLocalizedCatalog(ChannelInterface $channel, LocaleInterface
6363
);
6464
}
6565

66+
$localeCode = str_replace('-', '_', (string) $locale->getCode());
67+
if (1 !== preg_match('/^[a-z]{2}_[A-Z]{2}$/', $localeCode)) {
68+
throw new \InvalidArgumentException(sprintf('Gally requires locales in the "xx_XX" format (e.g. "en_US"), got "%s" for channel "%s". Configure a full locale in Sylius (Configuration > Locales).', $localeCode, (string) $channel->getCode()));
69+
}
70+
6671
return new LocalizedCatalog(
6772
$this->catalogCache[$channel->getCode()],
6873
$channel->getCode() . '_' . $locale->getCode(),
6974
(string) $locale->getName(),
70-
str_replace('-', '_', (string) $locale->getCode()),
75+
$localeCode,
7176
(string) $channel->getBaseCurrency()?->getCode(),
7277
);
7378
}

0 commit comments

Comments
 (0)