translation of functions ?
-
Hello, is it possible to translate functions, IDs, for instance
'title' => __( 'Preventivo', 'woocommerce' ), // TAB TITLE
echo 'richiesta noleggio volo per ' . $product->get_name(); // TAB TEXT
echo do_shortcode( '[form id="1046"]' ); // CHANGE SHORTCODE IF SECOND LANGUAGE IS DETECTEDor custom html and URLs I put in my widget, like
[button text="torna al catalogo" url="my-language-url"]
… I guess not, right?
-
- title => it’s in the po/mo file you can change it with locotranslate for static text,
- product->get_name it can be change directly with Falang i think the filter the_title is used in get_name
- do_shorcode falang do nothing on that with the falang pro you can use filter https://www.faboba.com/en/wordpress/falang-for-wordpress/documentation/134-how-to-use-lang-filtering.html .You can use php code to do the same
- widget classic ca be translated in Falang > String Translation or you can use a widget by language
I have resolved point 4 easily, but for the function I explained myself wrong. What I need is not just translate the words but trigger the function if the page is in english. So it would be exactly like point 4: having 2 functions and echo the italian/english respectively if the page is in italian or english. I’m not a developer so I wouldn’t even know if it’s possible to do something like that. (the function is one for adding a custom tab to the product page tabs)
You have to code a little with something like this
if ( function_exists( 'falang_current_language' ) ) {
$current_locale = falang_current_language('locale');
if ($current_locale == 'en_US'){
//my code for english
}
if ($current_locale == 'de_DE'){
//my code for german
}if you have a lot of language make a switch (use the locale it’s not supposed to change)
…thank you very much indeed for always being so helpful! I have edited my function and I must say that it works! If you would not mind to have a look at the final function, in case you spot any possible errors that could conflict with other things, I’d appreciate:
/* New Product Tab @ WooCommerce Single Product */
if ( function_exists( 'falang_current_language' ) ) {
$current_locale = falang_current_language('locale');
if ($current_locale == 'it_IT'){
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
function woo_new_product_tab( $tabs ) {
$tabs['docs'] = array(
'title' => __( 'Preventivo', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content',
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
global $product;
echo 'richiesta noleggio volo per ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1046"]' );
}
}
if ($current_locale == 'en_US'){
//my code for english, same as above but with strings translated
}
}you have to declare $current_locale before or you can have a warning if you disabled Falang
i use this code but it’s the same
if (class_exists( 'Falang' )) {
$current_locale = Falang()->get_current_language()->locale;
}i have update my developper documentation too
Brilliant! Thanks for the tip! Top support ??
…sorry Stéphane, I don’t mean to take advantage of your time but could you help me with a small tweak? I have noticed that the custom tab is added to every products, whereas I wish to have it only for one category. So I think I must add something like
if( is_product() && has_category( 'Phones' ) )
but I don’t know where I should insert it in the function we created. ?? I have made some attempts but I failed….
you can make it after the
if ( function_exists( 'falang_current_language' ) ) {
if( is_product() && has_category( 'Phones' ) ) {but i haven’t tested category test yet on wc , but i’m actually building a wc site , perhaps i can give you tomorrow more info but use probably more this
if(has_category(array('category_name_1', 'category_name_2')))
unfortunately it doesn’t work (the tab disappears)
if (class_exists( 'Falang' ))
if( is_product() && has_category( 'Phones' ) ) {
$current_locale = Falang()->get_current_language()->locale;I shall hope you will find out more….
i have found how to make it working perhaps not the right solution but works
if ( has_term( 'Phones', 'product_cat' ) ) {
echo 'found';
}…I’m not sure it works, or maybe it’s just me who coded it wrong. I have it like this:
if (class_exists( 'Falang' ))
if ( has_term( 'Phones', 'product_cat' ) ) {
echo 'found';
}
{
$current_locale = Falang()->get_current_language()->locale;
if ($current_locale == 'it_IT'){
//my code for italian
}
if ($current_locale == 'en_US'){
//my code for english
}and still have the custom tab on all products.
i give you the code to test if your product is from the phones category
you want to have the custom tab for just phone in this case it’s something like
//add code just for Phones category
if ( has_term( 'Phones', 'product_cat' ) ) {
if (class_exists( 'Falang' )) {
$current_locale = Falang()->get_current_language()->locale;
if ($current_locale == 'it_IT'){
//my code for italian
}
if ($current_locale == 'en_US'){
//my code for english
}
}
}You can put the code in the woo_new_product_tab function
so it was just some misunderstanding, yes I wish to have the custom tab just for the “phones” category, however it doesn’t work: the custom tabs has disappeared for all categories. But I have noticed that my permalink is structured like this: domain.com/shop-name/product-name/ and my category is domain.com/product_cat/phones/ So maybe we need a different code? Sorry for taking your time…
it’s easier in this case
you can do this
if ( has_term( 'Phones', 'product_cat' ) ) {
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
}or in the woo_new_product_tab you test the Phones term and you exit if it’s not the right one
then I’m doing something wrong, because I still have not the wished result. My current code is:
if ( has_term( 'noleggio', 'product_cat' ) ) {
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
}
if (class_exists( 'Falang' )) {
$current_locale = Falang()->get_current_language()->locale;
if ($current_locale == 'it_IT'){
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );where the last line is repeated. But I have also tried to remove it, with no luck
- You must be logged in to reply to this topic.