Skip to content

Instantly share code, notes, and snippets.

@timotheemoulin
Last active November 24, 2020 18:08
Show Gist options
  • Save timotheemoulin/262f829ced8eacfb1da499cee432e87e to your computer and use it in GitHub Desktop.
Save timotheemoulin/262f829ced8eacfb1da499cee432e87e to your computer and use it in GitHub Desktop.
Force ACF fields loaded over JSON fiels to be translated though gettext
<?php
/**
* Force ACF fields loaded over JSON fiels to be translated though gettext
*/
add_filter( 'acf/load_field',
/**
* Force ACF to try to translate fields even when they come from JSON.
*
* @param array $field
*
* @return array
*/
function ( array $field ): array {
$field['label'] = __( $field['label'] ?? '', 'custom-domain' );
$field['instructions'] = __( $field['instructions'] ?? '', 'custom-domain' );
$field['default_value'] = __( $field['default_value'] ?? '', 'custom-domain' );
$field['placeholder'] = __( $field['placeholder'] ?? '', 'custom-domain' );
$field['prepend'] = __( $field['prepend'] ?? '', 'custom-domain' );
$field['append'] = __( $field['append'] ?? '', 'custom-domain' );
return $field;
}
);
add_filter( 'acf/load_field_group',
/**
* Force ACF to try to translate groups even when they come from JSON.
*
* @param array $group
*
* @return array
*/
function ( array $group ): array {
$group['title'] = __( $group['title'], 'custom-domain' );
$group['description'] = __( $group['description'], 'custom-domain' );
return $group;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment