I have a select field, and I want its selected value to be automatically translated upon page saving.
I don’t know if this is the best way, but I thought of creating a page.update.after
hook to do the translation:
'page.update:after' => function($newPage, $oldPage) {
if ((string) $newPage->intendedTemplate() === 'variation-custom') {
try {
$page_en = $newPage->update([
'material' => 'translated value',
], 'en'); // en is the secondary language
} catch(Exception $e) {
echo $e->getMessage();
}
}
}
With this code, if I have translate: false
for the material
field in the blueprint, the field is not saved in the specified language file. Otherwise, it is saved but it’s value is blank.