Language file not loading - Wordpress Child Theme - wordpress

I'm trying to add a Dutch translation to a Wordpress theme.
I have edited .pot file (inside the theme) with POedit, and saved nl_NL .po and .mo (without any issues).
Naturally, I've made languages directory in my childtheme (called charityhub-child).
I have changed my code in the most basic form (taken from Wordpress Code reference).
My functions.php looks like this:
function wpdocs_child_theme_setup() {
load_child_theme_textdomain( 'charityhub', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wpdocs_child_theme_setup' );
Parent theme name = charityhub.
What seems to be the problem here ? Language files are not loading...

Related

Trying to translate Genesis Sample Child Theme?

I'm using Genesis Sample Child Theme for my website. There is a line of code in function.php:
load_child_theme_textdomain( genesis_get_theme_handle(), get_stylesheet_directory() . '/languages' );
I know this mean .po and .mo file must upload to wp-content/themes/genesis-sample/languages but I try to upload it to different folder wp-content/languages/themes and name the .po and .mo file genesis-sample-vi and website still translate.
Any idea why it still working no matter the code above?

Can not translate my wordpress website - no .pot file

I could not find a .pot file so I created one with Eazypo. There was no languages folder in the theme folder either. I created a "languages" folder and uploaded the newly created .pot file. I translated every string and uploaded the new .mo and .po files in the "languages" folder and I defined wp lang to have the value of the .mo file name. Not working.
Any ideas of what can be wrong or how to solve this issue?
Thank you
In order for your theme to load your translation files, you need to use the load_theme_textdomain() function.
Add the following code to your theme's functions.php file:
function wp756531_my_theme_setup(){
load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wp756531_my_theme_setup' );
Important Notes:
Make sure to change the 'my-theme' domain to the one your theme uses.
Make sure your translation files are named after your locale(s) (eg. es_ES.mo, sv_SE.mo, etc)

Wordpress: add new strings (and translate them) on child theme

I have a parent theme and I did create a child theme.
I did put a folder inside child theme /lang that overwrite parent and all went done. I did have my theme translate in italian and english.
Now I need to add a field to the registration form, so I use this code:
function tre_custom_woocommerce_register_form () {
?>
<p><label class="woocommerce-form__label woocommerce-form__label-for-checkbox inline">
<input class="woocommerce-form__input woocommerce-form__input-checkbox" name="privacy_mandatary" type="checkbox" id="privacy_mandatary" /> <span><?php _e('Autorizzo il trattamento dei miei dati, come riportato alla lett. A punti 1, 2 e 3 della policy privacy', 'mychildtheme-child'); ?></span>
</label></p>
So basically I did "create" another language domain (mychildtheme-child) different from parent.
In functions.php I did use this snippet:
function mychild_load_languages() {
load_child_theme_textdomain( 'mychildtheme-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'mychild_load_languages' );
And in the new folder called /languages/ (different from the other) I did put my .pot and the translations. But translates are not called, I have the theme only italian.
So, summarizing:
I have the parent theme with folder lang (it works)
I have the child with folder lang (it works). When I swith to English, I got all text translated (but not the new)
I have the child with folder languages (together with previous point) doesn't work.
According to the documentation of load_child_theme_textdomain, you need to also make sure you have a .mo file in your child themes root directory as well. Then you also need to ensure you have .po and .pot language files present in your language folder.
Also, you need to use the same text domain as the parent theme and not create a new text domain for your child theme. According to this comment in the documentation, whilst the translations can be in your child theme, it needs to imitate the parent theme as it's treated as one theme.
Excerpt from that comment:
function wpdocs_child_theme_setup() {
load_child_theme_textdomain( 'my_parent_theme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wpdocs_child_theme_setup' );
‘my_parent_theme’ = The name of the Main theme
The .mo files must use language-only filenames, like languages/de_DE.mo in your child theme directory.
For compatibility, make sure the languages folder is called the same as the parent themes language folder (/lang in your case) and the .mo, .po and .pot files are in a valid format.

How to make custom Wordpress plugin aware of .po and .mo files?

I am trying to add a translation to a plugin I wrote from scratch but after experimenting a while I'm not sure how to make Wordpress aware that there's a translation available for my plugin.
I'm not sure what else to try so I thought that someone more experienced could point out things I might need to change.
What I did so far:
Added either _e() or __() to the sentences I want to be translated in my plugin files.
Used Loco Translate plugin to generate a .pot file.
Opened .pot file in Poedit, (it displayed a list of all the strings I wanted to translate) translated plugin and generated .po and .mo files from it.
Moved .pot, .po and .mo to my-plugin/languages/.
Renamed files to my-plugin-pt.po and my-plugin-pt.mo.
Changed Wordpress site language to translated language. Language changed everywhere else but the plugin still renders in english.
Not really sure what to do next.
I've created a method that runs load_plugin_textdomain() while following these instructions from Wordpress and have added it as an action to my-plugin __construct():
my-plugin.php
public function __construct() {
// Other filters and actions...
add_action( 'plugins_loaded', array( $this, 'translation_init' ) );
} // __construct
function translation_init() {
load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
The language code at the end of the .po and .mo files was incorrect.
Changed from -pt.po to -pt_PT.po (did the same for .mo file) and it started working perfectly.
There's a list of the available language codes for Wordpress which I should have had a look before naming the files in the first place.

Why is my localization in wordpress not working?

I have created a theme.
All words and phrases are using either:
__('Word Here','mythemelocalpath')
or
_e('Word Here','mythemelocalpath')
I have made a folder called languages within the my new themes folder.
I created a .mo and .po and .pot file with poedit and placed them within the languages folder which is within my new theme folder.
The .mo, .po, .pot files are after the localization which is example: de_DE.mo
I then wrote this bit of code within the functions.php:
function mycustom_load_localization() {
// Retrieve the directory for the localization files
load_theme_textdomain( 'mythemelocalpath', TEMPPATH.'/languages' );
} // end custom_theme_setup
add_action('after_setup_theme', 'mycustom_load_localization');
I then enter the wp-config.php file and change the WP_LANG to de_DE
But for some reason its not working?
Can someone shed some light on this.
Thanks :)
Try this
load_theme_textdomain( 'mythemelocalpath', get_stylesheet_directory() . '/languages/' );
instead of
load_theme_textdomain( 'mythemelocalpath', TEMPPATH.'/languages' );
where get_stylesheet_directory() should give you the stylesheet directory path and it should be child theme save ;-)
Reference:
http://codex.wordpress.org/Function_Reference/get_stylesheet_directory

Resources