Skip to content

Instantly share code, notes, and snippets.

@umdevelopera
Last active January 10, 2024 19:36
Show Gist options
  • Save umdevelopera/bcc8c882ead5914845b489ece73b612d to your computer and use it in GitHub Desktop.
Save umdevelopera/bcc8c882ead5914845b489ece73b612d to your computer and use it in GitHub Desktop.
Example. A function used to translate choices of the Dropdown field in the Ultimate Member form. Uses the Polylang language switcher.
<?php
/**
* Get options for the "Seasons" field with Polylang.
*
* @return array
*/
function um_seasons_options() {
$lang = pll_current_language();
switch ( $lang ) {
default:
case 'en':
return array(
'winter' => 'Winter',
'spring' => 'Spring',
'summer' => 'Summer',
'fall' => 'Fall',
);
case 'es':
return array(
'winter' => 'Invierno',
'spring' => 'Primavera',
'summer' => 'Verano',
'fall' => 'Otoño',
);
case 'fr':
return array(
'winter' => 'Hiver',
'spring' => 'Printemps',
'summer' => 'Été',
'fall' => 'Automne',
);
}
}
@umdevelopera
Copy link
Author

umdevelopera commented Jan 4, 2024

Choices in the Ultimate Member fields are not translatable. You can use a workaround based on the Choices Callback feature to translate them. This feature uses a custom function to get an array of options for the field. You can verify a language inside the function to return an array with translated values. But keys must be the same!

The field settings example
UM Forms, Edit Form, Edit Field - Dropdown (use Choices Callback to translate values)

You can use this solution in addition to the the Ultimate Member - Polylang plugin.

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment