Sauter la navigation

Il s'agit du forum d'assistance technique de WPML, le plug-in multilingue pour WordPress.

Il est accessible à tous, toutefois seuls les clients de WPML peuvent y publier leurs messages. L'équipe du WPML répond sur le forum 6 jours par semaine, 22 heures par jour.

Sun Mon Tue Wed Thu Fri Sat
- 6:00 – 12:00 8:00 – 12:00 6:00 – 12:00 8:00 – 12:00 6:00 – 12:00 -
- 13:00 – 15:00 13:00 – 17:00 13:00 – 15:00 13:00 – 17:00 13:00 – 15:00 -

Fuseau horaire du supporter: America/Lima (GMT-05:00)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Nicolas V. Il y a 1 année et 11 mois.

Assisté par: Nicolas V..

Auteur Articles
juin 12, 2023 à 3:00 pm #13810811

antoineL-11

Hi,
I've created some shortcodes using this plugin : lien caché

WPML does not find the translatable strings from my custom snippets I've made with this plugin.

for example :
function display_cart_shortcode() {
$output = '';
if (is_user_logged_in()) {
$output .= '<div id="mini-cart" class="d-flex j-center a-center gap-8 pointer">';
$output .= '<span>' . __('Panier', 'your-text-domain') . '</span>';
}
else {
$output .= '<div id="mini-cart-2" class="d-flex j-center a-center gap-8 pointer">';
$output .= '' . __('Panier', 'custom-dev') . '';
}
$output .= '<i class="eicon-cart-medium">';

if (is_user_logged_in()) {
// Get the current user's WooCommerce cart items count
$cart_count = WC()->cart->get_cart_contents_count();

// Display the cart counter for logged-in users
$output .= '<span id="cart_counter" class="radius-100 white d-flex a-center j-center">' . $cart_count . '</span>';
}

$output .= '</div>';

return $output;
}

add_shortcode('display_cart', 'display_cart_shortcode');

Impossible to find tthe string "Panier" in WPML. I tried to scan the plugin within WPML localize plugin.
Is there another way ? The plugin Author says it is not compatible with wpml but I can't believe there is no workaround.

Regards

juin 12, 2023 à 4:11 pm #13811379

Nicolas V.
Supporter

Les langues: Anglais (English ) Français (Français )

Fuseau horaire: America/Lima (GMT-05:00)

Bonjour,

Bien que les codes personnalisés ne rentrent pas dans notre politique de support. Pourriez vous essayer d'utiliser la fonction __() en dehors de votre code et conditions en créant une variable?

$var = __('Panier', 'your-text-domain');

Vous pouvez ensuite appeler cette variable dans votre code.

Je ne suis pas familier avec ce plugin donc je ne sais pas comment ce code est inséré. Mais cela fonctionne avec une fonction personnalisée insérée dans functions.php

Le sujet '[Fermé] Translate strings from custom snippet' est fermé aux nouvelles réponses.