Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dokan WPML Guides #90

Open
MdAsifHossainNadim opened this issue Sep 26, 2024 · 5 comments
Open

Dokan WPML Guides #90

MdAsifHossainNadim opened this issue Sep 26, 2024 · 5 comments
Assignees

Comments

@MdAsifHossainNadim MdAsifHossainNadim self-assigned this Sep 26, 2024
@pronob1010
Copy link
Contributor

pronob1010 commented Sep 26, 2024

WPML issue: Text Detected in WPML String List but Not Translating after saving from Menu Manager

Issue Description: If any specific text is not being translated even when detected in the string list using WPML after saving the Menu manager

Solution

  1. Go to WPML → String Translation.
  2. Click on the "Translate texts in admin screens" link at the bottom of the page.
  3. Search for the text you want to translate on the next page.
  4. Select the text and click "Add to String Translation".
  5. Go back to String Translation and proceed to translate the selected text.

I hope this helps resolve your issue! 👍🏻

Note: For the first time, this menu will function perfectly without requiring any steps.

@osmansufy
Copy link

osmansufy commented Sep 26, 2024

WPML JavaScript Translation Issue

Overview of the Problem

WPML (WordPress Multilingual Plugin) currently has a limitation in its handling of JavaScript translations. While WPML successfully translates strings in PHP files, it does not automatically generate the necessary JSON files for translating strings in JavaScript files.

Detailed Description

  1. WordPress Translation Function: WordPress introduced the wp_set_script_translations() function to facilitate translations for JavaScript files.

  2. WPML's Current Behavior:

    • WPML generates .mo files for PHP strings in the /wp-content/languages/wpml directory.
    • However, WPML does not create the required JSON translation files for JavaScript strings.
  3. Result: JavaScript strings are not automatically translated by WPML, even when properly set up using WordPress's built-in localization functions.

Reference

This issue is documented in WPML's official errata:
WPML Errata: Translating strings from JavaScript files using wp_set_script_translations()

https://wpml.org/errata/woocommerce-checkout-block-fails-to-translate-some-values/

Impact

  • Multilingual websites using WPML may have inconsistent translations, with PHP-based content correctly translated but JavaScript-based content remaining in the original language.
  • This can affect user experience, especially in dynamic parts of the website that rely heavily on JavaScript.

Current Workaround

Until WPML addresses this issue,

Loco Translate: An Alternative Solution:

Unlike WPML, Loco Translate does support the creation of JSON files for JavaScript translations. This makes it a viable alternative for projects that heavily rely on JavaScript and require multilingual support.

  • Install and activate the Loco Translate plugin.
  • In your JavaScript file, use WordPress i18n functions as normal:
  • In PHP file, set up script translations:
  • wp_set_script_translations('your-script-handle', 'your-text-domain', plugin_dir_path(__FILE__) . 'languages');
  • Use Loco Translate's interface to provide translations for your strings.
  • Loco Translate will generate both .mo and .json files in your language directory.

Video Reference: Link

Long-term Solution

The permanent solution to this issue requires action from the WPML development team:

  1. WPML needs to implement support for generating JSON translation files for JavaScript strings.
  2. These JSON files should be automatically created alongside the existing .mo files.
  3. WPML should ensure compatibility with WordPress's wp_set_script_translations() function.

@MdAsifHossainNadim MdAsifHossainNadim changed the title Dokan WPML Guides SOP(Standard Operating Procedure) Dokan WPML Guides Oct 10, 2024
@pronob1010
Copy link
Contributor

pronob1010 commented Nov 12, 2024

WPML issue: Dynamic Text Translation Not Working

Issue Description: If any dynamic text shows on WPML but not translate after language shifting.

Solution

  1. Navigate to WPML → String Translation.
  2. Find the text that you need to translate.
  3. Check the name of that string (Note: The string will not translate without a name).
  4. If the name is correct, search the code for any preset text(if any) and check the length of the concatenated value we use for the register. If the key or name length exceeds 260 characters, WPML cannot translate it.

I hope this will help you to resolve your issue! 👍🏻

For more, you can check out this issue and the related PR: https://github.com/getdokan/client-issue/issues/182

@osmansufy
Copy link

osmansufy commented Nov 12, 2024

Dokan WPML - Custom/Dynamic String Translation Guide

This guide explains how to register and retrieve custom translatable strings using the Dokan WPML integration.

Overview

Dokan WPML provides two main methods for handling custom string translations:

  1. register_single_string() - Registers a string for translation
  2. get_translated_single_string() - Retrieves a translated string

Registering Custom Strings

Method Signature

public function register_single_string( $context, $name, $value )

Parameters

  • $context (string) - A grouping identifier for the string (e.g., 'dokan')
  • $name (string) - Unique identifier/name for the string
  • $value (string) - The actual string content to be translated

Example Usage

// Register a button text for translation
$this->register_single_string(
    'dokan', 
    'Dokan Request Quote Button Text: ' . $rule_id,  
    $button_text
);

// Register a shipping status
$this->register_single_string(
    'dokan',
    'Dokan Shipping Status: ' . $status,
    $status
);

Retrieving Translated Strings

Method Signature

public function get_translated_single_string( $original_value, $domain, $name, $language_code = null )

Parameters

  • $original_value (string) - The original untranslated string
  • $domain (string) - The context used when registering (e.g., 'dokan')
  • $name (string) - The unique identifier used when registering
  • $language_code (string|null) - Optional language code to retrieve specific translation

Example Usage

// Get translated button text
$translated_text = $this->get_translated_single_string(
    $text,
    'dokan',
    'Dokan Request Quote Button Text: ' . $rule->id
);

// Get translated shipping status
$translated_status = $this->get_translated_single_string(
    $status,
    'dokan',
    'Dokan Shipping Status: ' . $status
);

Implementation Workflow

In Dokan/ Dokan-pro

  1. DO action to register string .

example : after creation of RFQ rule .
path:modules/request-for-quotation/includes/Helper.php

 do_action( 'dokan_quote_rule_created', $inserted, $args, $wpdb->insert_id );
  1. Filter Text to get translatable string with required arguments
    example : To get button text of RFQ rule button text .
    path:modules/request-for-quotation/includes/Helper.php
     $rule->button_text = apply_filters( 'dokan_request_quote_button_text', $rule->button_text, $rule );

In Dokna Wpml :

Path : dokan-wpml.php

  1. Register String:
// In your action/hook handler
public function register_quote_button_text($action, $args, $rule_id) {
    if (!$action) {
        return;
    }
    $button_text = $args['button_text'];
    $this->register_single_string(
        'dokan',
        'Dokan Request Quote Button Text: ' . $rule_id,
        $button_text
    );
}
  1. Add Action Hook:
add_action('dokan_quote_rule_created', [$this, 'register_quote_button_text'], 10, 3);
  1. Retrieve Translation:
// In your display/render function
public function get_translated_dokan_request_quote_button_text($text, $rule) {
    return $this->get_translated_single_string(
        $text,
        'dokan',
        'Dokan Request Quote Button Text: ' . $rule->id
    );
}
  1. Add Filter:
add_filter('dokan_request_quote_button_text', [$this, 'get_translated_dokan_request_quote_button_text'], 10, 2);

Best Practices

  1. Consistent Context: Use consistent context strings (first parameter in registration) to group related translations.

  2. Unique Names: Create unique identifiers for strings by combining a descriptive prefix with dynamic IDs or Uniqe name:

    'Dokan Request Quote Button Text: ' . $rule_id

Troubleshooting

  1. If translations aren't appearing:

    • Verify string registration is successful
    • Check WPML String Translation module is active
    • Clear WPML's string translation cache
    • Ensure proper language is set
  2. For debugging, use WPML's string translation interface to verify:

    • String registration status
    • Correct context and name
    • Translation availability
  3. Common Issues:

    • Missing string registration
    • Incorrect context/name matching
    • Cache issues
    • WPML configuration problems

Related issue link

https://github.com/getdokan/client-issue/issues/220

@MdAsifHossainNadim
Copy link
Contributor Author

MdAsifHossainNadim commented Nov 14, 2024

WPML issue: Product category translation issue for different languages.

Issue Description: Translate vendor dashboard product categories & set category hierarchy for multiple languages.

Solution

  1. (WPML Multilingual CMS, WooCommerce Multilingual & Multicurrency, Dokan - WPML Integration) plugins is required.
  2. Go to WPML → Settings → Taxonomies Translation → Product categories (product_cat) <<<-------- (set as translatable)
  3. Go to WooCoomerce → WooCommerce Multilingual & Multicurrency → Categories → Translate all categories → Hierarchy Synchronization → Translate with base language <<<------------ (translate categories with base lang not translated lang)
  4. Flash the object/transient cache using Redis object cache plugin for maintain category hierarchy perfectly.
  5. Go to WoooCommerce Products → Categories <<<------------ (check the order of categories by visiting the translated category page)
  6. Set it up according to hierarchy, and re-check it in your vendor product edit/add page.

I hope this helps resolve your issue! 👍🏻

Fixed PR Link

#2364

@shams-sadek1981 shams-sadek1981 transferred this issue from another repository Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants