Skip to content

Commit f234766

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

2 files changed

Lines changed: 12 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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,20 @@ 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(
69+
'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).',
70+
$localeCode,
71+
(string) $channel->getCode(),
72+
));
73+
}
74+
6675
return new LocalizedCatalog(
6776
$this->catalogCache[$channel->getCode()],
6877
$channel->getCode() . '_' . $locale->getCode(),
6978
(string) $locale->getName(),
70-
str_replace('-', '_', (string) $locale->getCode()),
79+
$localeCode,
7180
(string) $channel->getBaseCurrency()?->getCode(),
7281
);
7382
}

0 commit comments

Comments
 (0)