I thought I should share how I managed to create a translation of custom fields and their labels on bilingual web site.
The problem with custom fields’ labels is that in the s2member classes the labels generated as plain text, not localized, thus it is not possible to translate them by adding custom labels to the .pot / .po file and generating .mo file for your language.
The way around it (until the s2member team does localization of labels) to replace non-localized custom fields labels with localized by using javascript in custom templates.
Here is tutorial how to create custom templates:
Add this script at the bottom of the template (amend using your own field labels and section titles) and you will be able to add all them to the pot / .po file:
var address = document.getElementById(‘s2member-pro-paypal-checkout-form-custom-reg-field-address-divider-section’);
var streetaddress = document.getElementById(‘s2member-pro-paypal-checkout-form-custom-reg-field-address-label’);
var city = document.getElementById(‘s2member-pro-paypal-checkout-form-custom-reg-field-city-label’);
var postcode = document.getElementById(‘s2member-pro-paypal-checkout-form-custom-reg-field-postcode-label’);
var country = document.getElementById(‘s2member-pro-paypal-checkout-form-custom-reg-field-country-label’);
// localized replacements
address.innerHTML = ‘<?php echo _x ("Postal Address", "s2member-front", "s2member"); ?>’;
streetaddress.innerHTML = ‘<?php echo _x ("Address", "s2member-front", "s2member"); ?>’;
city.innerHTML = ‘<?php echo _x ("City", "s2member-front", "s2member"); ?>’;
postcode.innerHTML = ‘<?php echo _x ("Postal Code", "s2member-front", "s2member"); ?>’;
country.innerHTML = ‘<?php echo _x ("Country", "s2member-front", "s2member"); ?>’;
And here how to localize the options labels in the select:
add_action(“ws_plugin__s2member_before_custom_field_gen”, “my_dynamic_field_options”);
function my_dynamic_field_options ($vars = array()) {
$_field = &$vars["__refs"]["_field"];
if ($_field[“id”] === “age_group”) {
$_field[“options”] = “Not selected|” . _x (‘Select Age Group’, ‘s2member-front’, ‘s2member’) . “|default” . “\n”;
$_field[“options”] .= “Under 20|” . _x (‘Under 20’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “20-30|” . _x (‘20-30’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “31-40|” . _x (‘31-40’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “41-50|” . _x (‘41-50’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “51-60|” . _x (‘51-60’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “61-70|” . _x (‘61-70’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “71-80|” . _x (‘71-80’, ‘s2member-front’, ‘s2member’) . “\n”;
$_field[“options”] .= “Over 80|” . _x (‘Over 80’, ‘s2member-front’, ‘s2member’);
}
}