migrator
migrator copied to clipboard
Locales aren't migrated to sites as expected
In v2 our site/settings/system.yaml
has these locales:
locales:
da:
name: Danish
full: da_DK
url: "{env:APP_URL}/"
en:
name: English
full: en_US
url: "{env:APP_URL}/en/"
sv:
name: Swedish
full: sv_SE
url: "{env:APP_URL}/sv/"
In v3 these are migrated to config/statamic/sites.php
as:
'sites' => [
'default' => [
'name' => 'Danish',
'locale' => 'da_DK',
'url' => '{env:APP_URL}/',
],
'en' => [
'name' => 'English',
'locale' => 'en_US',
'url' => '{env:APP_URL}/en/',
],
'sv' => [
'name' => 'Swedish',
'locale' => 'sv_SE',
'url' => '{env:APP_URL}/sv/',
],
],
I'd expect the key for Danish to be da
instead of default
.
A nice addition and helping hand, could be to convert the {env:APP_URL}
part of URLs:
$url = preg_replace('/{env:([A-Z0-9_]+)}/', '{env(\'$1\')}', $url);
I'm trying to rename default
to da
, renaming the respective content folders as well, then clearing cache, but the site just returns a 404 page - what am I missing?
Maybe you missed renaming the tree file?
Doesn't seem like it - the site just responds with a 404 error
Globals has also been renamed
Where's the homepage? In the pages
collection? (Probably)
Can you show content/collections/pages.yaml
?
That's it! I missed the collection structure changes 🙌
We dug into this. Looks like we intentionally change the first site to default
. It was for a reason, but we can't find the reason, yet. 😆
I guess it makes sense for single sites, but I'd imagine most multi sites use the key/handle for language selectors (with icons) like we do 🤷♂️
@jesseleite any update on this one?
@FrittenKeeZ Will dig into this one again soon 👍 I can't remember the reason, but leaving this issue open until we take another look.
Curious though, can you change the site handle from default
to your preferred handle post-migration? Should be a relatively easy find-and-replace in your project I would think?
@jesseleite yes I'm doing that during my testing, though it's easy to overlook various configurations and folders.
@jesseleite I just took a look at this, and since v3 works quite fine without using default
it all comes down to convenience of migrating content. The files affecting the conversion to default
are these:
trait Statamic\Migrator\Concerns\MigratesLocalizedContent
class Statamic\Migrator\GlobalSetMigrator
class Statamic\Migrator\PagesMigrator
class Statamic\Migrator\SettingsMigrator
Specifically it seems like you're using default
for the base content, instead of dynamically pulling the first site's key instead, so it should be possible to use the original keys all the way through.
We'll be using this tool for 7 sites, 3 of which are multi-language setups, so it would be nice not having to do manual handling every time we test the migration.