• Hello,

    We are very happy with Loco Translate. Works awesome!
    But now I have a question..

    I add a snipped in function.php (see below) and want to translate the new added string via loco translate. I use the plugin “woocommerce-subscriptions” to translate that. So I try to sync that “woocommerce-subscriptions” file but the new string is not showing up.

    Question is now, how do I have to translate new added strings via Loco Translate? ??

    function eg_show_product_removed_message( $url ) {
    	global $woocommerce, $eg_set_product_removed_message;
    
    	if ( isset( $eg_set_product_removed_message ) && is_numeric( $eg_set_product_removed_message ) ) {
    		wc_add_notice( sprintf( _n( '%s product has been removed from your cart. Products and subscriptions can not be purchased at the same time.', '%s products have been removed from your cart. Products and subscriptions can not be purchased at the same time.', $eg_set_product_removed_message, 'woocommerce-subscriptions' ), $eg_set_product_removed_message ), 'error' );
    	}
     
    	return $url;
    }
    add_filter( 'add_to_cart_redirect', 'eg_show_product_removed_message', 11, 1 );
    • This topic was modified 3 years, 8 months ago by niikk.
    • This topic was modified 3 years, 8 months ago by niikk.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tim W

    (@timwhitlock)

    Generally speaking you should not add new strings to another developer’s text domain (woocommerce-subscriptions in this case).

    To do this properly you should either make your code into a plugin with its own text domain, or create a child theme with your custom translations. Both of these routes are advanced topics and I can’t offer help with them.

    To do this your quick and dirty way you would have to regenerate the woocommerce-subscriptions.pot file (assuming there is one) to extract all strings including your new ones. Then sync your language files to that. I don’t know if that’s what you’re doing, or why it’s not working, but your code seems fine. To understand this process better see the help page on working with templates and follow the links related to sync functions.

    Thread Starter niikk

    (@niikk)

    @timwhitlock

    Thanks. So actually this code is in child theme function.php

    When I understand the process right, loco translate would load that “new” added translation file in woocommerce-subscriptions file because I press the sync button. Or how does that work?

    What I did:
    I only pressed “sync” in my woocommerce-subscriptions-de_CH.po file. In my understanding, then it would get all new strings..

    Maybe I miss something here ??

    • This reply was modified 3 years, 8 months ago by niikk.
    Plugin Author Tim W

    (@timwhitlock)

    actually this code is in child theme function.php

    Then read my guide on translating a child theme. You may find this a better route than hacking the woocommerce-subscriptions text domain which I have already advised against.

    I only pressed “sync” in my woocommerce-subscriptions-de_CH.po file. In my understanding, then it would get all new strings..

    Syncing a PO would only extract new sources if there was no POT file and you have not said whether there is one. If you want to improve your understanding of this, please read the documentation I linked to.

    Thread Starter niikk

    (@niikk)

    @timwhitlock

    Hmm.. Okey, so I do not want to translate my child theme. I add a custom code (for WooCommerce Subscriptions) in function.php and want to translate this new text string.

    Plugin Author Tim W

    (@timwhitlock)

    Ok. So do it that way then. I’ve given my recommendations, but you can do as you please.

    I’ve linked to documentation which explains the relationship between PO, POT and PHP files. Understanding this will enable you to add strings as you require. If you still don’t understand something, please say what it is.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Translate added string’ is closed to new replies.