Dokan Custom Text Translate
-
Hello ,
I have a code like this. With this code, I added a custom text (GST Number) field to the dokan plugin via php. But I can’t translate it via loco translate. What should I do to translate this? Can you help?
<p class="form-row form-group form-row-wide"> <label for="shop-phone"><?php esc_html_e( 'GST Number', 'dokan-custom-codes' ); ?><span class="required">*</span></label> <input type="text" class="input-text form-control" name="gst_id" id="gst_id" value="<?php if ( ! empty( $postdata['gst_id'] ) ) echo esc_attr($postdata['gst_id']); ?>" required="required" /> </p>
-
What is dokan-custom-codes?
Are you trying to add new source strings to an existing text domain?
Generally text domains refer directly to a plugin, (see WP docs). If this is the case then adding strings will mean generating a new template, and/or updating your existing PO files for that plugin (See Loco Translate’s sync function).
Unless you are the plugin author, then this is not advisable. If you want to maintain a bunch of new source strings that aren’t in the plugin already, then a better route would be to maintain a child theme (or even your own, separate plugin), and register your strings there.
This is an advanced topic, so if you need help please be more specific about what you need to do.
Everyone does what I’m trying to do. I add a custom text field to the Dokan registration page. Dokan’s guide for this process is in the link. https://wedevs.com/blog/406959/add-extra-fields-to-wordpress-registration-plugin/
I save the php page in the folder of my child theme. And I am updating this php file. Here I am adding a custom text field. However, when I synchronize this field, unfortunately, this field does not appear.
I save the php page in the folder of my child theme
Ok, so you’ve created a child theme called “dokan-custom-codes”, is that correct?
The examples in that Dokan article are inconsistent. First they show a child theme called “dokani-childtheme”, then they show example strings in a text domain called “dokan-custom-codes”, then later named “dokan-custom”. Everything should be named the same throughout the process.
However, when I synchronize this field, unfortunately, this field does not appear.
What are you synchronizing exactly? Have you followed the steps for extracting strings from source code, adding your language, and generating MO files?
To display your custom text you must generate translation files for your custom theme which must [ideally] be called “dokan-custom-codes”, or at least declare its text domain as “dokan-custom-codes” (see final point).
Generating your translations is done by finding your child theme in the Loco Translate themes section and adding your language. Have you done this? What files are generated?
Ensuring your translations are loaded before they are used is the important part. For WordPress to perform “just in time” translation loading, your text domain MUST match the child theme name. Otherwise you will have to write code to bootstrap the translations in your functions.php.
I don’t understand what you want to say. I will give you all the details step by step.
I didn’t create my own child theme, I already have one. I use Woodmart and Dokan plugin together. To ignore the dokan templates, I paste it into my child theme and fix it from there. This process is explained in the link I gave above.
Then I enter loco translate. When I say synchronization in the language file of my plugin, the text field in the code I added does not appear.
For example, I add a field called company title. However, I cannot translate this field to other languages. Because the company title does not come.
I don’t know how to be any clearer. I explained that your code won’t work unless the theme is called “dokan-custom-codes”.
Are you saying it will be fixed when I change this code like this?
<p class="form-row form-group form-row-wide"> <label for="shop-phone"><?php esc_html_e( 'GST Number', 'woodmart-child' ); ?><span class="required">*</span></label> <input type="text" class="input-text form-control" name="gst_id" id="gst_id" value="<?php if ( ! empty( $postdata['gst_id'] ) ) echo esc_attr($postdata['gst_id']); ?>" required="required" /> </p>
but it still didn’t work
I am aware that the plugin is free. But I’m having big problems because I can’t solve the problem. Could you please help me about the wrong coding done by dokan? I’d appreciate it.
the name of my child theme: woodmart-child
PHP Page Change :
<p class="form-row form-group form-row-wide"> <label for="company-title"><?php esc_html_e( 'Company Title', 'dokan-custom-codes' ); ?><span class="required">*</span></label> <input type="text" class="input-text form-control" name="company_title" id="company_title" value="<?php if ( ! empty( $postdata['company_title'] ) ) echo esc_attr($postdata['company_title']); ?>" required="required" /> </p>
Funchtions Change :
add_filter('wp_new_user_notification_email', 'jc_cwue_new_user_notification_email', 10, 3); function dokan_custom_seller_registration_required_fields( $required_fields ) { return $required_fields; }; add_filter( 'dokan_seller_registration_required_fields', 'dokan_custom_seller_registration_required_fields' ); function dokan_custom_new_seller_created( $vendor_id, $dokan_settings ) { $post_data = wp_unslash( $_POST ); $company_title = $post_data['company_title']; update_user_meta( $vendor_id, 'dokan_custom_company_title', $company_title ); } add_action( 'dokan_new_seller_created', 'dokan_custom_new_seller_created', 10, 2 ); /* Add custom profile fields (call in theme : echo $curauth->fieldname;) */ add_action( 'dokan_seller_meta_fields', 'my_show_extra_profile_fields' ); function my_show_extra_profile_fields( $user ) { ?> <?php if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } if ( ! user_can( $user, 'dokandar' ) ) { return; } $gst = get_user_meta( $user->ID, 'dokan_custom_company_title', true ); ?> <tr> <th><?php esc_html_e( 'Company Title', 'dokan-lite' ); ?></th> <td> <input type="text" name="company_title" class="regular-text" value="<?php echo esc_attr($gst); ?>"/> </td> </tr> <?php } add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } update_usermeta( $user_id, 'dokan_custom_company_title', $_POST['company_title'] ); }
Could you please help me about the wrong coding
There’s no need to post all of it. I’m not going to get into all of your code. The important parts (related to translation) are these:
esc_html_e( 'Company Title', 'dokan-custom-codes' );
esc_html_e( 'Company Title', 'dokan-lite' );
For whatever reason their examples switch between two text domains. Neither of them match your child theme text domain, so neither instance of Company Title will ever use your theme’s translation of this string.
if your theme is called woodmart-child, then (assuming it is set up
correctly) the code that WILL use your theme’s translations would be this:esc_html_e( 'Company Title', 'woodmart-child' );
Now, you’ve said you did this and it didn’t work. So, what did you do exactly?
Did you generate translations for your child theme, or did you go into your Dokan plugin and expect the Sync function to pick up your code? It won’t.
The steps for extracting new strings and updating languages are documented (See Loco Translate’s sync function). Do you follow this? If not, what is unclear?
If your child theme has a POT file, then the steps are these:
- Find
woodmart-child
in Loco Translate - Click Edit Template, then click Sync to update the file; then Save.
- Open your PO (translations) file for
woodmart-child
in Loco Translate (click the language name, or Edit link) - Click Sync to update the PO from the POT file; then Save.
If your child theme does NOT have a POT file then you can probably skip steps 1, and 2.
I can only make assumptions about your setup, so there’s no guarantee you won’t run into other problems. All I can say is this is how it is supposed to be done.
Unfortunately it didn’t work
- Find
- The topic ‘Dokan Custom Text Translate’ is closed to new replies.