Last active
January 10, 2024 19:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
You can use this solution in addition to the the Ultimate Member - Polylang plugin.
Related: