Skip Navigation

[Resolved] Creating French versions of my custom post type forms

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use two Forms to create posts in the same custom post type. One Form should be in French, and the other Form should be in English. I am considering using two different field groups, one for each language. I am not using a 3rd-party multilingual system or plugin.

Solution: Only create one Form and one Field Group. Use conditional HTML in the body of the Form to hide or show different translations based on the current page ID. Consider adding both languages to the option titles.

<div class="form-group">
    <label>
              [wpv-conditional if="('[wpv-post-id]' eq '12345')"]Book Title[/wpv-conditional]
              [wpv-conditional if="('[wpv-post-id]' eq '67890')"]Titre de Livre[/wpv-conditional]
            </label>
    [cred_field field="post_title" class="form-control" output="bootstrap"]
</div>

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-id

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1120927

Hello,

I have a site running Toolset where people sign up to become members by creating a custom post type on the front end.
My site runs in English, but I want to to have a French version of the form, it's fields and field options. I have tried doing this by creating a new a new field group for the Membership type, but that seems to translate pre-existing fields. Ideally a from in French would still create a member custom post type on the back end.

Hope that is clear enough.

Thank you.

#1121006

Hi, I would not recommend creating separate field groups for different languages. Then you can't really use custom fields in filters and searches. I would not recommend creating multiple Forms, either. One group of fields and one Form should be enough. Are you using a multilingual site system or plugin? If so, it may have a way for you to translate the field names shown on the Form.

For example, in WPML you can wrap the name of the field in a wpml-string shortcode and translate the name in WPML String Translation, like this:

	<div class="form-group">
		<label>[wpml-string context="your-unique-context" name="book-title"]Book Title[/wpml-string]</label>
		[cred_field field="post_title" class="form-control" output="bootstrap"]
	</div>

Then you can find the string "Book Title" in WPML String Translation and translate it into French. https://wpml.org/documentation/support/wpml-coding-api/shortcodes/

If you're not using WPML, then you can use conditional HTML to display different text based on some condition. Since you will probably display the Forms on different Pages of the site, you can test the ID of the current page. For example:

	<div class="form-group">
		<label>
                  [wpv-conditional if="('[wpv-post-id]' eq '12345')"]Book Title[/wpv-conditional]
                  [wpv-conditional if="('[wpv-post-id]' eq '67890')"]Titre de Livre[/wpv-conditional]
                </label>
		[cred_field field="post_title" class="form-control" output="bootstrap"]
	</div>

Replace 12345 with the numeric ID of the English page containing the English Form, and replace 67890 with the numeric ID of the French page containing the French Form. We have more information about conditional HTML available here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1124052

Hi Christian,

Sorry, it's been a long holiday weekend here in Canada.

I haven't had a chance to test what you are suggesting.

Would the WPML or HTML methods work for 'select' fields?

Thanks.

#1124058

You cannot apply conditional HTML to each option of a select field, so it might be necessary to include both languages in each option title. For example a select field might show two options like this:
- Book/Livre
- Essay/Essai
This is probably the simplest solution, combined with conditional HTML in other areas of the Form.

WPML is a full-featured multilingual software system, and you can translate each option individually. Types, Views, and WPML are all closely integrated. However, it is paid software and you would need some time to implement it. It might be overkill for what you're trying to accomplish.

#1125426

I am starting to test out Christian's suggestions and think I will be able to move ahead.

Thanks.