How to create a translation for a new child theme?

Community Forums Forums Internationalization and Translations How to create a translation for a new child theme?

This topic is: not resolved

This topic contains 2 replies, has 2 voices, and was last updated by  Stefano Garuti 1 year, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12590

    Stefano Garuti
    Participant
    Post count: 2

    Hallo,

    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!

    Stefano


    Italian web e-learning, social media freelance and consultant
    WPMania.it | WP Video course

    #13424

    David Decker
    Moderator
    Post count: 95

    Hi Stefano!

    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.

    Example:
    /** 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.
    -Dave :)


    #13439

    Stefano Garuti
    Participant
    Post count: 2

    David,

    thank you for your great post.

    Now I have all the information i need!

    Thank you again and have a good week!

    Stefano


    Italian web e-learning, social media freelance and consultant
    WPMania.it | WP Video course

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.