0

From everything I've read, you should only translate text strings via the WP translation functions like _e() or __(). However, I need a way to translate content submitted via a form. Is there some solution that will allow me to translate text outputted in a variable? Here's what I'm doing:

I'm working on a plugin for a company and they need the ability to set the description text for a checkbox via a form on the back end. The checkbox will be placed on a WooCommerce checkout page. They're using the WPML plugin, and want that text to be translatable. Here's what I naturally would want to do, but I know it's wrong:

woocommerce_form_field( 'my_checkbox', array(
     'type'     => 'checkbox',
     'class'    => array('input-checkbox'),
     'label'    => __( $sample_variable , 'woothemes'), 
     'required' => false,
    ),

Here's what I think I should do, but it doesn't seem to work:

woocommerce_form_field( 'my_checkbox', array(
     'type'     => 'checkbox',
     'class'    => array('input-checkbox'),
     'label'    => sprintf( __('%s', 'woothemes'), $mpo_check_box_desc ), 
     'required' => false,
    ),

Any help would be much appreciated, thank you!

1 Answer 1

2

You cannot translate text you don’t know. The translator must know the text before it was submitted – impossible.

The only solution is: add all language strings manually for each sub site.

4
  • Okay. So just to clarify, there is no possible way to allow them to insert text on an admin plugin page and have that text display properly on their WooCommerce checkout page. However, whatever translation files they have should be able to translate it if I use text and do something like 'label' => __('This is a checkbox', 'plugin-domain'), correct? I'm new to translating, so pardon me if my questions seem silly. Commented Feb 3, 2013 at 15:16
  • Yes, strings hard coded in a theme or plugin are translatable, unknown string are not.
    – fuxia
    Commented Feb 3, 2013 at 15:18
  • Awesome, thanks so much for your help! One more thing. I've never used WPML before, but it's my understanding that as long as I properly use the WordPress translation functions it will automatically translate in WPML. Do you know if that is the case, or do I need to do something special to make this work? Commented Feb 3, 2013 at 15:20
  • If you use always the same text domain it should work. I’m not familiar with WPML, I use Glotpress or Codestyling Localization usually.
    – fuxia
    Commented Feb 3, 2013 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.