Schema errors for ai_translate.settings
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3536092. -->
Reported by: [aporie](https://www.drupal.org/user/2987737)
Related to !778 !768
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When having several languages enabled and visiting the config form for the prompt translations (at /admin/config/ai/ai-translate), the form will generate a prompt and a model config for each language.</p>
<p>The problem is that, when saving this form, configuration is saved as is:</p>
<pre>use_ai_translate: 1<br>prompt: '...'<br>en_model: '...'<br>en_prompt: '...'<br>fr_model: '...'<br>fr_prompt: '...'<br># etc.</pre><p>This makes it hard to provide a proper schema, as these configs are not predictable.</p>
<p>In addition, it produces the following warning message:</p>
<blockquote><p>Schema errors for ai_translate.settings with the following errors: ai_translate.settings:entity_reference_depth missing schema, ai_translate.settings:en_model missing schema, ai_translate.settings:en_prompt missing schema, ai_translate.settings:fr_model missing schema, ai_translate.settings:fr_prompt missing schema, ai_translate.settings:de_model missing schema, ai_translate.settings:de_prompt missing schema. These errors mean there is configuration that does not comply with its schema. </p></blockquote>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<ol>
<li>Enable ai_translation</li>
<li>Add several languages to your website</li>
<li>Visit /admin/config/ai/ai-translate</li>
<li>Save the form (with or without changes)</li>
<li>You should see a warning message about schema (as above).</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>There is no simple fix for this as it requires a bit of revamping (and probably a hook_update).<br>
I think one approach would be to put these configs under a predictable name, such as "language_settings", so we can describe it properly in ai_translate.schema.yml.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>- Revamping ai/modules/ai_translate/src/Form/AiTranslateSettingsForm.php form<br>
- Revamping ai_translate.schema.yml to provide the proper schema<br>
- Identifying where this config is used, to update the way they are retrieved<br>
- Writing a hook_update to move the config in their new config object (language_settings).<br>
- Adding / Updating tests</p>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
<p>Any suggestions to fix this is welcomed.</p>
issue