Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Neighborhood › Overriding translation with child theme
New Landing › How can we help? › Themeforest Theme Support › Neighborhood › Overriding translation with child theme
- This topic has 11 replies, 5 voices, and was last updated 9 years by Rui Guerreiro – SUPPORT.
-
Posted in: Neighborhood
-
April 6, 2015 at 12:25 am #163137
Hi there,
I’m trying to override the FR translation for the “Sold Out” product badge (on product image) but with no success. With the help of this previous thread and Google, here is what I tried so far (pure guess):
My updated fr_FR.po (edited with PoEdit) and fr_FR.mo files are in a themes/neighborhood-child/languages folder.
I then added the code below in my child theme functions.php file :
<?php function my_child_theme_setup() { load_child_theme_textdomain( 'neighborhood-child', get_stylesheet_directory() . '/language' ); } add_action( 'after_setup_theme', 'my_child_theme_setup' ); ?>
Unfortunately that doesn’t work. Could you please help spotting what I’m doing wrong?
thank you,
AmmieApril 6, 2015 at 12:34 pm #163245Hi,
My colleague, Mr. Laranz will assist you shortly.
Thanks
MohammadApril 6, 2015 at 1:01 pm #163248Thank you Mohammad.
There is a typo in my code snippet above. The path is ‘/languages‘, with a S.
Thanks.
AmmieApril 6, 2015 at 1:04 pm #163249Hi,
You most welcome. I am glad that you managed to resolve the issue.
Thanks
MohammadApril 6, 2015 at 1:15 pm #163252Ooops,
No, I didn’t managed to resolve the issue. There was just a typo in my first message that could have made Mr Laranz confused. But my code still doesn’t work, with or without typo.
Sorry for the confusion.
AmmieApril 7, 2015 at 7:20 am #163339Hi,
Please live your website first and provide login detail to inspect the issue.
Thanks
MohammadApril 7, 2015 at 7:48 am #163363Hi,
It should work, Try this two codex official information about child theme translation.
1. http://codex.wordpress.org/Child_Themes#Internationalization
2. https://codex.wordpress.org/Function_Reference/load_child_theme_textdomainLet us know,
Thanks,
laranz.April 7, 2015 at 2:00 pm #163455Thank you Laranz,
Well. I’m still unable to make that work. I attach a screenshot of my files name/path along with the content of my child theme functions.php file.
So far I tried :
– Change translation for “My account” –> Doesn’t work. Apparently the issue is not woocommerce-specific
– Placed the add_action line before the function –> Doesn’t work
– Placed my modified fr_FR.po and fr_FR.mo files in neighborhood-child root directory and used load_child_theme_textdomain( ‘neighborhood-child’ ); –> Still no success
– Uploaded fresh WordPress 4.1.1 files (except wp-content and wp-config.php) and fresh Neighborhood 2.16 files –> Still doesn’t work
– Checked my .po file is actually modified and my child theme activated : Yes!
– Disabled all plugins except those required for the theme, cleaned database and deleted transients –> No change
– I don’t know if this is expected or not but when I change define(‘WPLANG’, ‘fr_FR’); for define(‘WPLANG’, ‘en_US’); in the wp-config.php file, then the site frontend is still in French.
– NB : I do not have WPML nor cache plugins installed.Do you see anything else I could try?
Thanks a lot,
AmmieAttachments:
You must be logged in to view attached files.April 8, 2015 at 1:32 pm #163769I just had the same problem, and made it work. It seems that the translations have use same textdomain as the parent theme. You need to translate both the “swiftframework” domain, and “woocommerce”.
This works for me, loading the same translations twice …
<?php function my_child_theme_setup() { load_child_theme_textdomain( 'swiftframework', get_stylesheet_directory() . '/languages' ); load_child_theme_textdomain( 'woocommerce', get_stylesheet_directory() . '/languages' ); } add_action( 'after_setup_theme', 'my_child_theme_setup' ); ?>
April 8, 2015 at 2:31 pm #163792Thanks @matteth
You are totally right, we should designate the text domain we want to overide.
In this case is swiftframework.-Rui
April 8, 2015 at 4:02 pm #163816Aaaaah… thank you sooooo much matteh for the clue 🙂
In my case I had to do it the other way (using ‘swiftframework’ as textdomain keeps loading the parent theme .mo file).
In case other users would have the same issue, I needed to override the translation for the “Out of Stock” badge :1 – In the child-theme functions.php file, I keep neighborhood-child (or whatever name) as textdomain :
<?php function my_child_theme_setup() { load_child_theme_textdomain( 'neighborhood-child', get_stylesheet_directory() . '/languages' ); } add_action( 'after_setup_theme', 'my_child_theme_setup' ); ?>
2 – In theme/child-theme/woocommerce/single-product/product-image.php, I edited the file to replace ‘swiftframework’ with ‘neighborhood-child’. For instance :
// Line 24 - Change echo '<span class="out-of-stock-badge">' . __( 'Out of Stock', 'swiftframework' ) . '</span>'; // To echo '<span class="out-of-stock-badge">' . __( 'Out of Stock', 'neighborhood-child' ) . '</span>';
As overriding woocommerce .mo file specifically I did it the “woo” way and saved my custom .mo file in a wp-content/languages/woocommerce folder. As far as I can see, Neighborhood theme and Woocommerce do not translate the same strings.
Ammie
April 8, 2015 at 4:07 pm #163818Thanks for sharing the way you did it.
-Rui -
Posted in: Neighborhood
You must be logged in and have valid license to reply to this topic.