Content dimension: Migrate language from en_US to en_GB

Hi,

so we are about to finish a project and now I have been informed that the english version of the site should not be in English US, but in English UK. In most cases no one will recognise this.
However there are some cases (for example date or time formatting) where it is relevant.

Fortunetly we only have to dimension hashes. One for de_DE (primary language) and one for en_US.

Is there some easy way to change the current content dimension en_US to en_GB?
The URLs must not change (the URL part is “en”, not “en-us”).

I thought about changing all en_US nodes manually on database level:

neos_contentrepository_domain_model_nodedata:

  • dimensionvalues: Replace “en_US” with “en_GB” in the JSON code.
  • dimensionhash: Replace old en_US hash to en_GB hash

neos_contentrepository_domain_model_nodedimension:

  • value: Replace “en_US” with “en_GB”

And change the ElasticSearch index configuration.

So my questions are:

  • Should this work or am I missing something?
  • Is there a better (safer) way to do this?

Regards
Leif

So it turns out. Atleast in this case, it really was that simple.

For anyone having the same task in the future:

I created at simple doctrine migration:

declare(strict_types=1);

namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20220221114102 extends AbstractMigration
{
    private string $oldLocale = 'en_US';
    private string $newLocale = 'en_GB';

    private string $oldHash = '4f534b1eb0c1a785da31e681fb5e91ff';
    private string $newHash = '20c5b67e4cd39e143f960aa54c542b03';

    public function getDescription(): string
    {
        return 'Migrate en_US to en_GB';
    }

    public function up(Schema $schema): void
    {
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addLanguageMigration($this->oldLocale, $this->newLocale, $this->oldHash, $this->newHash);
    }

    public function down(Schema $schema): void
    {
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addLanguageMigration($this->newLocale, $this->oldLocale, $this->newHash, $this->oldHash);
    }

    private function addLanguageMigration(string $fromLocale, string $toLocale, string $fromHash, string $toHash): void
    {
        $this->addSql('
            UPDATE neos_contentrepository_domain_model_nodedata
            SET dimensionvalues = REPLACE(dimensionvalues, :from_locale, :to_locale), dimensionshash = :to_hash
            WHERE dimensionshash = :from_hash',
            [
                'from_locale' => '"'.$fromLocale.'"',
                'to_locale' => '"'.$toLocale.'"',
                'from_hash' => $fromHash,
                'to_hash' => $toHash,
            ]
        );

        $this->addSql('UPDATE neos_contentrepository_domain_model_nodedimension SET value = :to_locale WHERE value = :from_locale', [
            'from_locale' => $fromLocale,
            'to_locale' => $toLocale,
        ]);
    }
}

Changed the content dimension configuration:

Neos:
  ContentRepository:
    contentDimensions:
      language:
        icon: icon-language
        label: 'Language'
        default: de_DE
        defaultPreset: de_DE
        presets:
          de_DE:
            label: 'Deutsch'
            values:
              - de_DE
            uriSegment: de
          en_GB:
            label: 'English'
            values:
              - en_GB
            uriSegment: en

en_GB was en_US before.

Changed the hash of the ElasticSearch index:

Flowpack:
  ElasticSearch:
    indexes:
      default:
        'my-index-name-20c5b67e4cd39e143f960aa54c542b03': # en_GB (was en_US before)

Then:

  1. Execute the migration
  2. Flush cache
  3. Build node index

Seems to work fine.

2 Likes

Cool, thx for also posting the solution!

Just wondering… Isn’t that what the RenameDimension Transformation is about?

Well … you might be right. I must have missed that… :roll_eyes: