Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1036434
    Oxley-2014
    Participant

    Hello,
    I needed to translate some strings so I have followed the steps described in the Theme.co tutorial:
    “How to translate the X theme into other languages”.

    I have added this function in the functions.php file of the child theme.

    add_action( ‘after_setup_theme’, ‘load_child_language’ );
    function load_child_language() {
    load_child_theme_textdomain( ‘__x__’, get_stylesheet_directory() . ‘/languages’ );
    }

    I had also to use this other function in order to translate the word “Search” in the placeholder of the search box.

    add_filter(‘gettext’, ‘translate_text’ );
    function translate_text($translated) {
    $translated = str_ireplace(‘Search’, ‘MY TRANSLATION’, $translated);
    return $translated;
    }

    Doing so I ended up with many problems. Had to use a backup. Tried again and once again had to deal with problems. I do not see what can be wrong here but I have lost too much time because of this.
    So I have abandoned the idea of using .po and .mo files.

    Fact is after the “incident” I have realized I was still using the former files organization: the old “x-child-CHOSEN STACK” and not the new “x-child”. Could this be the problem?

    Anyway I have translated the concerned strings inside the concerned files except for the search box placeholder. For this specific string I still use the above function.

    The “concerned files” that have been modified (translation done in the file itself) are these two:

    wp-content/themes/x/framework/functions/global/navbar.php
    wp-content/themes/x/framework/views/global/_content-none.php

    Actually I want to translate:
    “Type and Press “enter” to Search”
    and
    “Nothing to Show Right Now, etc.”

    In order to keep the modifications in case of updates I have placed “navbar.php” and “_content-none.php” in
    wp-content/themes/x-child/framework/functions/global/navbar.php
    and
    wp-content/themes/x-child/framework/views/global/_content-none.php

    I have created the missing folder and sub-folder when required to build the exact same path except it is now “x-child” instead of “x”.

    “_content-none.php” does its job but not “navbar.php”

    There is still the text “Type and Press “enter” to Search” showing in english.

    What have I done wrong?
    Could you help me, please?

    Regards,
    Oxley

    #1036444
    Oxley-2014
    Participant
    This reply has been marked as private.
    #1036448
    Oxley-2014
    Participant

    The idea of a translation inside the file here is to avoid to use a function in the “functions.php” file since it has caused some trouble.
    Thank you.

    #1036913
    Rad
    Moderator

    Hi there,

    Just to confirm based on your explanation, it’s only the “Type and Press “enter” to Search” that isn’t translating, right?

    “_content-none.php” does its job but not “navbar.php”

    By the way, navbar.php is different from _navbar.php, navbar.php contains function names that can only customize through child theme’s functions.php, while _navbar.php is a template.

    Hence, the solution is adding this code through child theme’s functions.php with your translation.

      function x_navbar_searchform_overlay() {
    
        if ( x_get_option( 'x_header_search_enable' ) == '1' ) :
    
          ?>
    
          <div class="x-searchform-overlay">
            <div class="x-searchform-overlay-inner">
              <div class="x-container max width">
                <form method="get" id="searchform" class="form-search center-text" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                  <label for="s" class="cfc-h-tx tt-upper"><?php _e( 'Type and Press &ldquo;enter&rdquo; to Search', '__x__' ); ?></label>
                  <input type="text" id="s" class="search-query cfc-h-tx center-text tt-upper" name="s">
                </form>
              </div>
            </div>
          </div>
    
          <?php
    
        endif;
    
      }
      add_action( 'x_before_site_end', 'x_navbar_searchform_overlay' );
    

    Functions aren’t template that can be copied as file to override it, you can only override functions through functions.php

    Thanks!

    #1037517
    Oxley-2014
    Participant

    Hello,
    Thanks Rad for your answer.

    Yes, it’s only the “Type and Press “enter” to Search” that isn’t translating.
    And yes we talk about “navbar.php” and not about “_navbar.php”.

    I do not want to customize any function. I just want to change the string that is showing. (Unless changing a string is also a customization?)

    In both case I see <?php _e( “SOMETHING to show on the website”, ‘__x__’ ); ?> inside the code.
    I have change “SOMETHING to show on the website” by something else and I have put these two modified files in the child theme.

    As a non-programmer-guy I do not see why putting these two modified files in the child theme provides the desired result in one case and not in the other one.

    I guess the explanation is… I dont get it because I am not a programmer-guy :-(((

    But again in case I was not clear in my explanation, if I modify
    “SOMETHING to show on the website”
    in the files “_content-none.php” and “navbar.php” in the theme (AND i do not put these two modified files in the child theme) then it works!!!

    I understand the sentence “Functions aren’t template that can be copied as file to override it, you can only override functions through functions.php” but why in the case of “_content-none.php” does it work?
    I guess “php _e()” is a function by itself, isn’t it?

    If you understood me 100% then the solution is to use your function or to modify “_content-none.php” and “navbar.php” in the theme and to remember that each update means a new modification.

    Thanks again.

    Regards,
    Oxley

    #1037832
    Rad
    Moderator

    Hi there,

    No, you can’t put navbar.php in the child theme, it’s a function file that should be only customized through functions.php. That’s why navbar.php and _navbar.php are different.

    but why in the case of “_content-none.php” does it work?

    Because it’s a template file and not a function file, and you can just drop the file in the child theme.

    Let’s start with folder structures,

    This is where the templates are, any file can be copied to child theme

    \x\framework\views\

    And this is where the function files, and can’t be copied to the child theme, all functions here are only customizable through functions.php (eg. pluggable functions https://codex.wordpress.org/Pluggable_Functions ).

    \x\framework\functions\

    For clarification, _content-none.php is a template file, while navbar.php is a function file. It’s the _navbar.php that is the template. Copying navbar.php will not work since it’s not a template, it will only work if you will redeclare the same function code (with customization) to child theme’s functions.php.

    _content-none.php isn’t related to navbar.php, you can’t use _content-none.php for comparison. They have different purpose.

    Thanks!

    #1044594
    Oxley-2014
    Participant

    Rad,
    Hello,

    Sorry for my late answer.

    Thank you for your patience and your explanations. Now I get it!
    Thanks again.

    Actually before you answered I was continuing to look for a solution and I found on the forum somebody sharing a code allowing to translate “Type and Press “enter” to Search”.
    The idea is different than using the functions.php file. It uses some Javascript code through the Customizer.
    Here is the code:

    (function($){ 
      	$('.cfc-h-tx.tt-upper').text('My desired TRANSLATION');
    })(jQuery)

    Since both solutions work my question consists in knowing what solution is better in terms of speed/ressource usage if there is any difference. And in general is it better to use some custom code or to work with the functions.php file?

    Thanks in advance for your advice.

    Regards,
    Oxley.

    #1044680
    Rue Nel
    Moderator

    You’re welcome!
    Thanks for letting us know that it has worked for you.

    #1046365
    Oxley-2014
    Participant

    Rue Nel,
    Hello,

    Did you notice there was a question hidden in my extremely long message?

    Regards,
    Oxley

    #1046517
    Rad
    Moderator

    Hi there,

    Utilizing functions.php is much better, and with caching, performance is no issue.

    Javascript only runs on browser, hence, user may able to see the translation, but search engines will not.

    Thanks!

    #1047530
    Oxley-2014
    Participant

    Rad,
    Hello,

    Thank you for your clarification!

    Regards,
    Oxley

    #1047802
    Friech
    Moderator

    You’re more than welcome, glad we could help.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1036434 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>