latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Translation of Custom Registration Fields

Home Forums Community Forum Translations Translation of Custom Registration Fields

This topic contains 9 replies, has 5 voices. Last updated by  Natasha Bernal 3 years, 9 months ago.

Topic Author Topic
Posted: Wednesday Oct 24th, 2012 at 8:04 am #29507
Cord
Username: mailbeez

I use a number of Custom Registration/Profile Fields.

Using the poedit / .pot files approach am able to translate the labeles of the default fields.

Using a text-editor I added those lines at the end of the .pot file:

#: custom
msgctxt "s2member-front"
msgid "Comment?"
msgstr "Kommentar?"

In po-edit I can edit this new translation item.

But it is not replaced in the registration form.

How can i add translations for custom field labels?

cheers
cord

List Of Topic Replies

Viewing 9 replies - 1 through 9 (of 9 total)
Author Replies
Author Replies
Posted: Saturday Oct 27th, 2012 at 5:45 pm #29938
Jesus Altuve
Username: jaltuve

Hi!

I found your question looking for an answer myself, so I decided to figure it out. You simply need to add this to your theme functions.php:

function translate_custom_field($rec) {
        $label = $rec['field']['label'];
        $rec['field']['label'] = _x($label, "s2member-front", "s2member");
        return $rec;
}
add_action("ws_plugin__s2member_during_custom_registration_fields_before_custom_fields", "translate_custom_field");
add_action("ws_plugin__s2member_during_profile_during_fields_during_custom_fields_before", "translate_custom_field");

Obviously, make sure you DO have the entry in your .po file. The above fix assumes you are using
getext po/mo files and that the file is properly named (s2member-xx_YY.mo) and is in the plugins root directory and NOT inside the s2member plugin directory.

xx_YY is the locale, as in es_ES or en_US

Posted: Monday Oct 29th, 2012 at 5:31 am #30004
Cord
Username: mailbeez

great solution! works like a charm!

Posted: Monday Oct 29th, 2012 at 6:36 am #30007
Cord
Username: mailbeez

Almost there…

The Section titles “Title for this new section? ” are not translated – wonder what hooks to apply there?

To get the wordpress default strings translated, I needed to add this code to my functions.php:

//http://boring-group.com/blog/2011/03/04/how-to-load-plugin-translation-mo-files-with-qtranslate/
if (function_exists(‘qtrans_getLanguage’)) {
load_default_textdomain();
}

looks like qtranslate sets the language differently so WPLANG is not longer respected. Loading the default text domain again helps

Posted: Monday Nov 5th, 2012 at 4:11 am #30620
Cord
Username: mailbeez

figured out myself, the final solution for both custom fieldnames and section titles looks like this:

function translate_custom_field($rec)
{
    // labels
    $label = $rec['field']['label'];
    $rec['field']['label'] = _x($label, "s2member-front", "s2member");

    $label = $rec['field']['sectitle'];
    $rec['field']['sectitle'] = _x($label, "s2member-front", "s2member");

    return $rec;
}
Posted: Thursday Jan 10th, 2013 at 3:22 pm #36879
david
Username: solar

Hi, I have just tried to translate labels of custom fields in this way, but it doesn’t work.

Any other ideas?

Posted: Tuesday Feb 19th, 2013 at 9:14 am #42476
Oriol Boan
Username: orboan

Hi,
the php code to put in the functions.php themes works to translate the name of the custom registration field, but what if this custom registration field is a dropdown box: how to translate the text of the items shown in the dropdown box?

Thank u!

Posted: Saturday Feb 23rd, 2013 at 11:55 am #43046
Oriol Boan
Username: orboan

From this code:

function translate_custom_field($rec)
{
    // labels
    $label = $rec['field']['label'];
    $rec['field']['label'] = _x($label, "s2member-front", "s2member");

    $label = $rec['field']['sectitle'];
    $rec['field']['sectitle'] = _x($label, "s2member-front", "s2member");

    return $rec;
}

you tell that ‘label’ is the string bound to custom fieldnames, and ‘sectitle’ tha string bound or used to identify the section title names in custom regostration fields. So my qüestion is how have you found these bindings or relations, my goal is to find the string related or bound to the items belonging to a custom registration dropdown box, to make those items translatable.
Thanks!

Posted: Sunday Feb 24th, 2013 at 1:42 pm #43122
Oriol Boan
Username: orboan

Hello again,
from the next code shown above (see first message):

add_action("ws_plugin__s2member_during_custom_registration_fields_before_custom_fields", "translate_custom_field");
add_action("ws_plugin__s2member_during_profile_during_fields_during_custom_fields_before", "translate_custom_field");

I think these actions are meant for the translations to be shown in the registration form (first add_action) a in the profile (second add_action). Assuming this is correct, the result i my website is that the custom fields are translated in the profile form, but not in the registration form, being this registration form the one I generate with the paypal pro forms with a code like next:

[s2Member-Pro-PayPal-Form register="1" level="0" ccaps="" desc="Signup now, it's Free!" custom="mydomain.com" tp="0" tt="D" captcha="clean" /]

How can I make the custom reg fields also being translated in the registration form? Should I have to change the value for the first parameter in the first add_action? Add another add_action?
Thank you.

Posted: Sunday Mar 24th, 2013 at 12:08 pm #45593

Hi Guys,

I don’t really understand the process. Not working for me.

I’ve added the custom string into the POT file, then generated the PO / MO file uploaded in the PLUGINS ROOT and also POT and PO and MO in the translation folder as it was not working…

#: custom
msgctxt "s2member-front"
msgid "Country"
msgstr "Pays"

when I open the POTin POEDIT, I have an error on the string.

how do you determine #: custom ??
as in the POT file it’s always very precise on where the string is located
like #: s2member/includes/classes/custom-reg-fields.inc.php:328

what will be the right location #: for the custom fields ?

function.php code described in the topic was added also.
and codestyling once scanned again the PO file… doesn’t show the new string.

+ It’s not changing anything in the PROFILE PAGE.

I’m using qtranslate and I have a lot of custom files.
Why can’t we use the languages shortcodes in the fields ???
Like

[:en]Country[:fr]Pays
or 
<!--:en-->Country<!--:--><!--:fr-->Pays<!--:--> 

Anyone can help to use languages shortcodes for qttranslate or the solution described in the topic ?

Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.