• I had to add this to a custom plugin in order for the translations to load on the front end:

    function s4cuz_customizr_domain( $mofile, $domain = '' ) {
    	if ( $domain == 'customizr' && ! file_exists( $mofile ) ) {
    		$theme_dir = get_template_directory();
       		$mofile = $theme_dir . '/inc/lang/' . get_locale() . '.mo';
    	}
    	return $mofile;
    }
    add_action( 'load_textdomain_mofile', 's4cuz_customizr_domain', 9, 2 );

    The directory indicated as …/themes/customizr/languages/ doesn’t exist.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Sorry don’t understand,
    theme translation isn’t loaded by default?

    Thread Starter ReactorShop

    (@reactorshop)

    It can’t be loaded because it’s looking for the translation files in a …/themes/customizr/languages/ folder that doesn’t exist.

    The folder where the translations files are located is …/themes/customizr/inc/lang/

    Sorry, still don’t understand, what is looking for the translations files in the wrong directory?
    https://github.com/nikeo/customizr/blob/master/inc/class-fire-init.php#L464

    this theme looks in the correct directory

    Thread Starter ReactorShop

    (@reactorshop)

    This is what’s causing the issue (from wp-includes/class-wp-theme.php):

    public function load_textdomain() {
    	if ( isset( $this->textdomain_loaded ) )
    		return $this->textdomain_loaded;
    
    	$textdomain = $this->get('TextDomain');
    	if ( ! $textdomain ) {
    		$this->textdomain_loaded = false;
    		return false;
    	}
    
    	if ( is_textdomain_loaded( $textdomain ) ) {
    		$this->textdomain_loaded = true;
    		return true;
    	}
    
    	$path = $this->get_stylesheet_directory();
    	if ( $domainpath = $this->get('DomainPath') ) <------ THIS!
    		$path .= $domainpath;
    	else
    		$path .= '/languages'; <------ IT TAKES THIS DEFAULT VALUE!
    
    	$this->textdomain_loaded = load_theme_textdomain( $textdomain, $path );
    	return $this->textdomain_loaded;
    }

    Which is called by this function (in that same file):

    public function display( $header, $markup = true, $translate = true ) {
    	$value = $this->get( $header );
    	if ( false === $value ) {
    		return false;
    	}
    
    	if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) )
    		$translate = false;
    
    	if ( $translate )
    		$value = $this->translate_header( $header, $value ); <-- THIS
    
    	if ( $markup )
    		$value = $this->markup_header( $header, $value, $translate );
    
    	return $value;
    }

    Where $header == ‘AutorURI’ and $value = ‘https://presscustomizr.com/&#8217;

    Which is called by the class construct in …/themes/customizr/inc/init.php

    if ( ! class_exists( 'TC___' ) ) :
      class TC___ {
        //Access any method or var of the class with classname::$instance -> var or method():
        static $instance;
        public $tc_core;
        public $is_customizing;
        public static $theme_name;
        public static $tc_option_group;
    
        function __construct () {
          self::$instance =& $this;
    
          /* GETS INFORMATIONS FROM STYLE.CSS */
          // get themedata version wp 3.4+
          if( function_exists( 'wp_get_theme' ) ) {
            //get WP_Theme object of customizr
            $tc_theme                     = wp_get_theme();
    
            //Get infos from parent theme if using a child theme
            $tc_theme = $tc_theme -> parent() ? $tc_theme -> parent() : $tc_theme;
    
            $tc_base_data['prefix']       = $tc_base_data['title'] = $tc_theme -> name;
            $tc_base_data['version']      = $tc_theme -> version;
            $tc_base_data['authoruri']    = $tc_theme -> {'Author URI'}; <--- THIS!
          }

    So,

    1. The Customizr class construct assigns the theme’s Autor URI, among other values.
    2. The WordPress Theme class decides that the Autor URI needs translation.
    3. Since the Customizr translation domain is not loaded yet, the WordPress theme class decides to load it on its own, assigning default values.
    4. The translation file is not found, so the customizr domain is not loaded.

    Thanks for this explanation but still:
    1) I understand that when retrieving this:
    $tc_base_data['authoruri'] = $tc_theme -> {'Author URI'};
    that load_textdomain will be called, and since no Domain Path is specified no textdomain, hence no theme_textdomain will be loaded in that case
    2) Cannot understand why this should impact on the overall theme_textdomain loading since, as I reported above, the theme afterwards succesfully calls the function load_theme_textomain passing the right path.
    3) If you were right I, and the other users, will not be able to see strings translated in their language. This doesn’t look to be the case.
    I can successfully see translated strings in Italian for example.

    Also, since the code you posted looks for the attribute “Domain Path” I made this test, this suggests that if the author adds that attribute among the style’s attributes (it the style.css file), since he calls that $tc_base_data['authoruri'] = $tc_theme -> {'Author URI'}; <--- THIS! which we know that calls load_textdomain then he doesn’t need this:
    https://github.com/nikeo/customizr/blob/master/inc/class-fire-init.php#L464

    Anyway, I cannot reproduce your issue. Textdomain is loaded fine here.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Translations only load while on the admin side’ is closed to new replies.