You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Symfony 7 / DoctrineExtension v3.16.1 (Version details are below)
Translateable does not create a database entry in the translation table when the string is the same as in the default locale. Example in symfony7:
$studyField = newStudyField();
// Make sure we're on default locale English$studyField->setTranslatableLocale('en');
$studyField->setName('Software Engineering');
$em->persist($studyField);
$em->flush();
// Fail: does not create an entry in translation table due to similar name (But we want this name)// Switch to German$studyField->setTranslatableLocale('de');
$studyField->setName('Software Engineering');
$em->persist($studyField);
$em->flush();
// Ok: for a non-similar string value a proper entry in translation table for "de" is created// $studyField->setTranslatableLocale('de');// $studyField->setName('Software Foo');// $em->persist($studyField);// $em->flush();
This is a problem for our custom auto translation. We don't see a valid German entry, and therefore the autotranslation creates entry "Software Entwicklung", which is not what we want.
It's counter-intuitive in other regards as well.
Why does it happen? Is there a specific reason for it? Can I deactivate this behavior?
I also appreciate hints from where in the code this behavior originates.
Thanks!
Configuration
# config/packages/stof_doctrine_extensions.yamlstof_doctrine_extensions:
default_locale: en# If you want your application to fall back to the default locale’s translation when a specific locale’s translation is not available, you should set this to true. It's not necessary if you expect every locale to have its own complete set of translations or if you handle missing translations at the application logic level.translation_fallback: true# true: when saving $foo->setName('bar') also creates a row in ext_translations for default locale, otherwise notpersist_default_translation: trueorm:
default:
# Enable behaviorstranslatable: truesluggable: truetimestampable: true
$ composer show --latest 'doctrine/*'
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version
Direct dependencies required in composer.json:
doctrine/doctrine-bundle 2.12.0 2.12.0 Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle 3.3.1 3.3.1 Symfony DoctrineMigrationsBundle
doctrine/orm 3.2.1 3.2.1 Object-Relational-Mapper for PHP
Transitive dependencies not required in composer.json:
doctrine/cache 2.2.0 2.2.0 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, m...
doctrine/collections 2.2.2 2.2.2 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common 3.4.4 3.4.4 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depen...
doctrine/dbal 3.8.6 4.0.4 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations 1.1.3 1.1.3 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations...
doctrine/event-manager 2.0.1 2.0.1 The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector 2.0.10 2.0.10 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and...
doctrine/instantiator 2.0.0 2.0.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer 3.0.1 3.0.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations 3.8.0 3.8.0 PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for...
doctrine/persistence 3.3.3 3.3.3 The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine objec...
doctrine/sql-formatter 1.4.0 1.4.0 a PHP SQL highlighting library
PHP version
$ php -v
PHP 8.3.8 (cli) (built: Jun 6 2024 19:58:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.8, Copyright (c) Zend Technologies
with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies
The text was updated successfully, but these errors were encountered:
The problem is Doctrine itself. After changing to the second locale, for Doctrine, the name remains the same and does not trigger a change in the entity. Therefore no translated database entry is created.
Workaround: create a dummy field that will mark the entity dirty in case of a locale change. This will then trigger an update:
#[ORM\Column(type: 'string', length: 5, nullable: true)]
private $dummyLocale;
public function setTranslatableLocale($locale) : self
{
$this->locale = $locale;
$this->dummyLocale = $locale; // This will trigger a change
return $this;
}
Environment
Symfony 7 / DoctrineExtension v3.16.1 (Version details are below)
Translateable does not create a database entry in the translation table when the string is the same as in the default locale. Example in symfony7:
This is a problem for our custom auto translation. We don't see a valid German entry, and therefore the autotranslation creates entry "Software Entwicklung", which is not what we want.
It's counter-intuitive in other regards as well.
Why does it happen? Is there a specific reason for it? Can I deactivate this behavior?
I also appreciate hints from where in the code this behavior originates.
Thanks!
Configuration
Package
Doctrine packages
PHP version
The text was updated successfully, but these errors were encountered: