ThemeShaper Forums » Thematic

[closed]

Thematic Child Theme Language

(19 posts)
  • Started 1 year ago by bogh
  • Latest reply from helgatheviking
  • This topic is resolved
  1. bogh
    Member

    Hi,

    I was wondering if it's possible to add language files to a thematic child theme, but without overwriting the default thematic language files.
    Basically what I need to do is to add some words, or phrases, used on my child theme.

    How can I do that? Do you know a tutorial for this? Or you have a good explanation for this? ... I couldn't find a relevant answer for my question, so maybe you can help.

    Thanks a lot.

    Posted 1 year ago #
  2. bogh
    Member

    Do you know a thematic child theme with language support?
    Maybe if I see how one is made I will answer my own question...

    Posted 1 year ago #
  3. bogh
    Member

    I have added this to my child theme's functions.php

    // Translate, if applicable
    load_child_theme_textdomain('aeryn', CHILDTHEME . '/languages');
    
    $locale = get_locale();
    $locale_file = CHILDTHEME . "/languages/$locale.php";
    if ( is_readable($locale_file) )
    	require_once($locale_file);

    I have a language folder, with POT, PO, MO.

    And here is what I am trying to make translatable:

    <div class="author_box_author"><?php sprintf(__('by', 'aeryn')) ?> <?php  the_author_posts_link(); ?></div>

    Can someone tell me what am I doing wrong please?

    Posted 1 year ago #
  4. middlesister
    Member

    The process of adding language support to a child theme is exactly the same as for any regular theme. The parent theme will not be affected by your child theme textdomain. You seem to be doing the right thing. My only question is if/how you have generated the POT file. I think that Poedit can do this (but I don't remember exactly how).

    Basically, every time you add/change something you need to also update that POT file. And for every language, create the po/mo file (poedit creates the .mo automatically) and translate the strings in each.

    Like I said, it all looks correct to me. Are you having a problem?

    Posted 1 year ago #
  5. bogh
    Member

    Thank you for your reply.
    As I said above I have POT, PO, MO, in the languages folder. (*aeryn.pot, fr_FR.po and .mo, generated with Poedit ), so I don't really know what I am missing. I will post the content of the pot & po files, maybe I am doing something wrong there.

    "aeryn" is the name of my thematic child theme.

    Posted 1 year ago #
  6. bogh
    Member

    The files from the languages folder:

    aeryn.pot

    msgid ""
    msgstr ""
    "Project-Id-Version: Aeryn\n"
    "Report-Msgid-Bugs-To: \n"
    "POT-Creation-Date: \n"
    "PO-Revision-Date: \n"
    "Last-Translator: Full Name <your@email.com>\n"
    "Language-Team: \n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: 8bit\n"
    "X-Poedit-SourceCharset: utf-8\n"
    "X-Poedit-KeywordsList: __;_e\n"
    "X-Poedit-Basepath: .\n"
    "X-Poedit-SearchPath-0: c:\\xampp\\htdocs\\development\\wp-content\\themes\\aeryn\n"
    
    #: c:\xampp\htdocs\development\wp-content\themes\aeryn/admin/admin-functions.php:367
    msgid "by"
    msgstr ""

    fr_FR.po

    msgid ""
    msgstr ""
    "Project-Id-Version: Aeryn\n"
    "Report-Msgid-Bugs-To: \n"
    "POT-Creation-Date: \n"
    "PO-Revision-Date: \n"
    "Last-Translator: Full Name <your@email.com>\n"
    "Language-Team: \n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: 8bit\n"
    "X-Poedit-Language: French\n"
    "X-Poedit-Country: FRANCE\n"
    "X-Poedit-SourceCharset: utf-8\n"
    "X-Poedit-KeywordsList: __;_e;_c\n"
    "X-Poedit-Basepath: .\n"
    
    #: c:\xampp\htdocs\development\wp-content\themes\aeryn/admin/admin-functions.php:367
    msgid "by"
    msgstr "du"

    fr_FR.mo

    Þ•,<PQtTÉbyProject-Id-Version: Aeryn
    Report-Msgid-Bugs-To:
    POT-Creation-Date:
    PO-Revision-Date:
    Last-Translator: Full Name <your@email.com>
    Language-Team:
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    X-Poedit-Language: French
    X-Poedit-Country: FRANCE
    X-Poedit-SourceCharset: utf-8
    X-Poedit-KeywordsList: __;_e;_c
    X-Poedit-Basepath: .
    du

    I have a feeling that the links are wrong, I saw other themes using something like:

    "X-Poedit-Basepath: .\n"
    "X-Poedit-SearchPath-0: .\n"
    "X-Poedit-SearchPath-1: ..\n"
    
    #: ../admin/admin-functions.php:367
    msgid "by"
    msgstr ""

    Thank you :)

    Posted 1 year ago #
  7. middlesister
    Member

    I think you are right. I'm not an expert but it would be logical to use relative paths, so that the string is referred relative to the language file.

    And just for troubleshooting: you are sure you have defined WP_LANG in your config file?
    Have you added the code to a hook or is it straight in your functions.php?

    Posted 1 year ago #
  8. bogh
    Member

    Yes, am sure I have defined the WPLANG correctly, because the rest of the theme is translated to french.
    wp-config.php

    define('WPLANG', 'fr_FR');

    I have tried the method with relative paths, but no luck at all.

    I have also found something on here: http://support.presswork.me/discussion/175/recommended-way-of-handling-translations/p1

    // Setup the language file
    add_action( 'after_setup_theme', 'pw_child_theme_language' );
    
    function pw_child_theme_language() {
    	// Make theme available for translation
    	// Translations can be filed in the /languages/ directory
    	load_child_theme_textdomain("child-theme-slug", STYLESHEETPATH . '/admin/languages');
    
    	$locale = get_locale();
    	$locale_file = STYLESHEETPATH . "/languages/$locale.php";
    	if ( is_readable( $locale_file ) )
    		require_once( $locale_file );
    }

    But I am not sure if this does not do the same thing as my code from above.

    Posted 1 year ago #
  9. middlesister
    Member

    So I gather everything is in french except that single word? I.e. the thematic translation is working but not your child theme's?

    Double check the CHILDTHEME constant. If you give the path it needs to be the full path to your child theme, like STYLESHEETPATH . '/languages' FWIW, I have used the regular load_theme_textdomain() and it worked for me.

    What you posted above is doing the same thing, but added to a hook. That is what I meant with my question above. You could try using that, it is a good idea in general to attach things to hooks to ensure they fire when they are supposed to. Just replace your own textdomain and make sure the path points to your languages folder (i.e. '/languages' instead of '/admin/languages')

    Posted 1 year ago #
  10. bogh
    Member

    I have modified the thematic's french files and they are working just fine. But I can't make that word translatable.
    I have tried the hooked code too, but the same answer: nothing happens.

    I have double checked everything for hours, I have tried with more themes, in many ways, I really don't understand what's wrong. Tried it on localhost and live site too.
    Is not my PHP code good?

    With some small modifications to the PHP code, the word does not even show up.
    The word does show up (*but does not translate) when:

    <?php printf(__('by', 'aeryn')) ?>
    or
    <?php sprintf(_e('by', 'aeryn')) ?>

    The word does NOT show up when:

    <?php sprintf(__('by', 'aeryn')) ?>

    So I am not at least sure how I should do my simple php line.

    Would be possible for you to send me your child theme with language support?

    Posted 1 year ago #
  11. middlesister
    Member

    Heh, I'm sure I could dig it out somewhere if you really need to but it is old and not using the current thematic.

    Just took a closer look at your translated string. What are you using the sprintf() for? If you just want to echo you can write

    <div class="author_box_author"><?php _e('by', 'aeryn') ?> <?php  the_author_posts_link(); ?></div>

    __() is for returning the string for a function, _e() is for echoing out into (x)html pages.

    Posted 1 year ago #
  12. bogh
    Member

    The code is in a function, so I suppose I should use just __(), but this does not display the word anymore, and _e() is displaying it but with no translation.

    Please send me the theme somehow, it's my only hope now, because I couldn't find any other thematic child theme with language support. Is there a way to send you a private message on this forum? so I don't post my email here :)

    Thanks a lot.

    Posted 1 year ago #
  13. middlesister
    Member

    It's not a matter of the code being within a function or not, but rather if the translated string is USED by a function or ECHOED out. If your function is creating html, then you still use _e().

    Sorry there's no PM function that I know of. Could you maybe send me your child theme instead? I'll see if I can troubleshoot. My email is invistruct at gmail dot com.

    Posted 1 year ago #
  14. bogh
    Member

    Thanks you a lot for your time, I am going to send you the acamas theme with my modifications.

    Posted 1 year ago #
  15. this isn't my strong suit but

    // Setup the language file
    add_action( 'after_setup_theme', 'pw_child_theme_language' );
    
    function pw_child_theme_language() {
    	// Make theme available for translation
    	// Translations can be filed in the /languages/ directory
    	load_child_theme_textdomain("child-theme-slug", STYLESHEETPATH . '/admin/languages');
    
    	$locale = get_locale();
    	$locale_file = STYLESHEETPATH . "/languages/$locale.php";
    	if ( is_readable( $locale_file ) )
    		require_once( $locale_file );
    }

    is exactly how i am doing it myself... i just have yet to actually try to translate anything. is that not working?

    Posted 1 year ago #
  16. bogh
    Member

    That one is working too, my problem was on the php line, I haven't used sprintf/printf(__() or _e()) correctly, all I needed for this was _e().

    I use it like that now:

    load_child_theme_textdomain("acamas", STYLESHEETPATH . '/languages');
    
    $locale = get_locale();
    $locale_file = STYLESHEETPATH . "/languages/$locale.php";
    if ( is_readable( $locale_file ) )
    	require_once( $locale_file );

    Now it works perfectly.

    Posted 1 year ago #
  17. sounds like a facepalm moment :)

    this should work to echo

    <?php _e('by', 'aeryn')); ?>

    and to return:

    <?php __('by', 'aeryn')); ?>
    Posted 1 year ago #
  18. bogh
    Member

    Yes, that is right :))

    I have lost almost a day with it, but at least I have learned something. :)

    Thank you.

    Posted 1 year ago #
  19. sure thing. wish i had read your post a bit more closely the first time.... could've solved that sooner.

    Posted 1 year ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.