Metadata translation fields
-
Hi!
When translating custom fields NOT added via ACF, the default field in the translation interface is an
input
of typetext
.In many scenarios, this is not suitable, because metadata can be anything from a one-liner to a block of text, or a data structure, like a JSON string.
There is no hook to alter this behavior (the field is hard-coded in
falang/admin/views/edit_post_page.php
).
A way for developers working with field meta not part of ACF would be to emulateget_field_objects
– which is a lot of work, error-prone, limited in scope, and too opinionated.A low-hanging fruit (but far from ideal) solution to make sure all text-based meta can actually be edited would be to use a
textarea
for all the custom meta, infalang/admin/views/edit_post_page.php
:<input type="text" name="<?php echo $key; ?>" id="<?php echo $key; ?>" value="<?php echo isset($previous_value[0])?esc_attr($previous_value[0]):''; ?>" class="falang">
to be replaced with:
<textarea name="<?php echo $key; ?>" id="<?php echo $key; ?>" class="falang"><?php echo isset($previous_value[0])?esc_attr($previous_value[0]):''; ?></textarea>
A better solution (a bit more work-intensive, but with the bulk of the responsibility offloaded to the developer integrating the falang plugin) would be to expose a filter for each translatable field for developers to override the translation interface of the field.
Indeed, some meta fields may be stored one way, but displayed and edited in another, for example stored as JSON but edited with a custom interface.
Another use case would be that some values are to be selected from a pre-determined set, and not free text, where free text could introduce bugs. This is specially important given that a translation interface is not aimed at developers, but at users.
One current example of this limitation is the featured image, which many users struggle with (unless they’ve been trained) because they must input an attachment ID.For now, I can add a JS snippet to alter the input I need and transform them to
textarea
, or editfalang/admin/views/edit_post_page.php
and lose the changes at each plugin update, which is not ideal.
Having the possibility to override the interface would be the best solution, limiting the amount of maintenance for falang itself while opening the potential for a whole array of possible improvements.
- The topic ‘Metadata translation fields’ is closed to new replies.