getdokan / dokan-wpml

WPML compatibility with dokan plugin
5 stars 10 forks source link

Dokan WPML Guides #90

Open MdAsifHossainNadim opened 1 month ago

MdAsifHossainNadim commented 1 month ago
pronob1010 commented 1 month ago

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 commented 1 month ago

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

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.

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.
pronob1010 commented 4 days ago

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 commented 4 days ago

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

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

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

  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
    );
    }
  2. Add Action Hook:

    add_action('dokan_quote_rule_created', [$this, 'register_quote_button_text'], 10, 3);
  3. Retrieve Translation:

    // In your display/render function
    public function get_translated_button_text($text, $rule) {
    return $this->get_translated_single_string(
        $text,
        'dokan',
        'Dokan Request Quote Button Text: ' . $rule->id
    );
    }
  4. Add Filter:

    add_filter('dokan_request_quote_button_text', [$this, 'get_translated_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:

    'Dokan Request Quote Button Text: ' . $rule_id
  3. Error Handling: Always verify that strings are registered before attempting translation:

    if (function_exists('wpml_object_id_filter')) {
       // Proceed with translation
    }
  4. Documentation: Add comments to indicate which strings are translatable:

    // Translatable string - Quote button text
    $button_text = apply_filters('dokan_request_quote_button_text', $text, $rule);

Common Use Cases

  1. Dynamic Button Text:
    
    // Registration
    $this->register_single_string('dokan', 'Button: ' . $id, $text);

// Retrieval $translated = $this->get_translated_single_string($text, 'dokan', 'Button: ' . $id);


2. **Status Messages**:
```php
// Registration
$this->register_single_string('dokan', 'Status: ' . $status_key, $message);

// Retrieval
$translated = $this->get_translated_single_string($message, 'dokan', 'Status: ' . $status_key);
  1. Custom Labels:
    
    // Registration
    $this->register_single_string('dokan', 'Label: ' . $key, $label);

// Retrieval $translated = $this->get_translated_single_string($label, 'dokan', 'Label: ' . $key);



## 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 commented 2 days ago

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