Open MdAsifHossainNadim opened 1 month ago
I hope this helps resolve your issue! 👍🏻
Note:
For the first time, this menu will function perfectly without requiring any steps.
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.
WordPress Translation Function: WordPress introduced the wp_set_script_translations()
function to facilitate translations for JavaScript files.
WPML's Current Behavior:
.mo
files for PHP strings in the /wp-content/languages/wpml
directory.Result: JavaScript strings are not automatically translated by WPML, even when properly set up using WordPress's built-in localization functions.
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/
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.
wp_set_script_translations('your-script-handle', 'your-text-domain', plugin_dir_path(__FILE__) . 'languages')
; Video Reference: Link
The permanent solution to this issue requires action from the WPML development team:
.mo
files.wp_set_script_translations()
function.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
This guide explains how to register and retrieve custom translatable strings using the Dokan WPML integration.
Dokan WPML provides two main methods for handling custom string translations:
register_single_string()
- Registers a string for translationget_translated_single_string()
- Retrieves a translated stringpublic function register_single_string( $context, $name, $value )
$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// 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
);
public function get_translated_single_string( $original_value, $domain, $name, $language_code = null )
$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// 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
);
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
);
}
Add Action Hook:
add_action('dokan_quote_rule_created', [$this, 'register_quote_button_text'], 10, 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
);
}
Add Filter:
add_filter('dokan_request_quote_button_text', [$this, 'get_translated_button_text'], 10, 2);
Consistent Context: Use consistent context strings (first parameter in registration) to group related translations.
Unique Names: Create unique identifiers for strings by combining a descriptive prefix with dynamic IDs:
'Dokan Request Quote Button Text: ' . $rule_id
Error Handling: Always verify that strings are registered before attempting translation:
if (function_exists('wpml_object_id_filter')) {
// Proceed with translation
}
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);
// 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);
// 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
Redis object cache
plugin for maintain category hierarchy perfectly.I hope this helps resolve your issue! 👍🏻