migrator icon indicating copy to clipboard operation
migrator copied to clipboard

Locales aren't migrated to sites as expected

Open FrittenKeeZ opened this issue 3 years ago • 11 comments

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

FrittenKeeZ avatar Aug 31 '21 15:08 FrittenKeeZ

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?

FrittenKeeZ avatar Sep 02 '21 14:09 FrittenKeeZ

Maybe you missed renaming the tree file?

jasonvarga avatar Sep 02 '21 14:09 jasonvarga

Doesn't seem like it - the site just responds with a 404 error image

Globals has also been renamed

FrittenKeeZ avatar Sep 02 '21 14:09 FrittenKeeZ

Where's the homepage? In the pages collection? (Probably) Can you show content/collections/pages.yaml?

jasonvarga avatar Sep 02 '21 15:09 jasonvarga

That's it! I missed the collection structure changes 🙌

FrittenKeeZ avatar Sep 03 '21 06:09 FrittenKeeZ

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. 😆

jasonvarga avatar Sep 07 '21 13:09 jasonvarga

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 🤷‍♂️

FrittenKeeZ avatar Sep 07 '21 13:09 FrittenKeeZ

@jesseleite any update on this one?

FrittenKeeZ avatar Oct 04 '21 09:10 FrittenKeeZ

@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 avatar Oct 06 '21 14:10 jesseleite

@jesseleite yes I'm doing that during my testing, though it's easy to overlook various configurations and folders.

FrittenKeeZ avatar Oct 06 '21 14:10 FrittenKeeZ

@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.

FrittenKeeZ avatar Nov 19 '21 09:11 FrittenKeeZ