January 17, 2013 at 5:37 am #12590Stefano GarutiMember
I need to provide a translation for a child theme I created from scratch.
The strings in the theme are all enclosed the WP localization function with their own textdomain (i.e.
__('Some text','my_child_textdomain'), etc)
The whole Genesis is translated using the tips by Remkus on his blog (here).
Now I need your help 😉
Do I need to create a new .po file?
Where I have to put it (and the .mo file)? In my_child_dir/languages/ folder ?
How can I "tell" to the child theme to load it? Do I have to use
load_child_theme_textdomain()(I see it used in some child themes)
Thanks for your help!
January 21, 2013 at 1:14 am #13424David DeckerMember
Good topic, hehe 🙂
You're already on the right path!
You need to add the loading function for the textdomain just right after Genesis init function in child theme functions.php -- load it early before any strings are defined in child theme, that's best practice.
/** Set Localization (do not remove) */
load_child_theme_textdomain( 'your-unique-textdomain', apply_filters( 'child_theme_textdomain', get_stylesheet_directory() . '/languages', 'your-unique-textdomain' ) );
--> as you can see here's already the path for the lang files defined, "/languages/" sub folder within child theme folder -- also best practice but you can use any path within child theme of course 🙂
Actual lang files have the convention to only be named with the locale for themes & child themes, so for example: it_IT.mo and it_IT.po for Italian language. WP actually only needs the binary .mo file but it's best practice to also upload the .po file so you could edit it anytime you need it.
As for the adding of the textdomain and Gettext syntax you did all right --- just remember to only use one unique textdomain for your child theme. Best practice here is to use the theme slug as the textdomain string. Do not use variables or constants here as this is not right here.
If you did all the above you can then scan your child theme files with Poedit Editor to create a .pot file and then open the .pot catalog and create a .po file of it. Tip: enable "Create .mo file on saving" in Poedit settings so every time you hit save it creates/updates the actual .mo file.
I hope that helps.
January 21, 2013 at 2:14 am #13439
- You must be logged in to reply to this topic.