Hy我試圖在插件代碼中獲取當前語言。我試着用get_locale(),但它總是給我en_us。我試圖找到WordPress代碼引用的解決方案,但沒有發現任何工作。WP在插件代碼中獲取語言環境
在的問題是插件WooCommerce,文件WC-車-的functions.php 有行:
$added_text = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', sizeof($titles), 'woocommerce'), wc_format_list_of_items($titles));
和
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(wc_get_page_permalink('cart')), esc_html__('View Cart', 'woocommerce'), esc_html($added_text));
我想要得到這樣的結果:
if($language == 'hr') { $added_text = sprintf(_n('%s je dodan u košaricu.', '%s su dodani u košaricu.', sizeof($titles), 'woocommerce'), wc_format_list_of_items($titles));
} else { $added_text = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', sizeof($titles), 'woocommerce'), wc_format_list_of_items($titles)); }
if($language == 'hr') { $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(home_url().'/kosarica'), esc_html__('Pogledaj košaricu', 'woocommerce'), esc_html($added_text));
} else { $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(wc_get_page_permalink('cart')), esc_html__('View Cart', 'woocommerce'), esc_html($added_text)); }
通常情況下,我會通過從URL創建語言來解決此問題,但該網站沒有語言在URL中。
我忘了提及,網站使用Polylang插件語言。 – Rufflady
哎呀,意在添加,作爲評論,但將它作爲答案。特別是如果它有效。 – craniumonempty