• Resolved ezemans

    (@ezemans)


    Hi, first want to say thanks for this plugins! it’s great!. Im making a theme and im using this. It’s was a great solution for me, but I having some problems:

    Notice: Undefined variable: domains in D:\wamp\www\framework\wp-content\plugins\theme-check\checks\textdomain.php on line 119
    
    Warning: array_unique() expects parameter 1 to be array, null given in D:\wamp\www\framework\wp-content\plugins\theme-check\checks\textdomain.php on line 119
    
    Warning: implode(): Invalid arguments passed in D:\wamp\www\framework\wp-content\plugins\theme-check\checks\textdomain.php on line 120

    Lines 119 and 120 of textdomain.php:
    $domains = array_unique($domains);
    $domainlist = implode( ‘,’, $domains );

    How can I fix it? Maybe it’s a problem in functions.php?
    Thanks!

    https://wordpress.org/plugins/theme-check/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    This usually happens when you have a translation function with a variable parameter. Translation functions can only translate strings, not variables. Fix your function call and the error will go away.

    Thread Starter ezemans

    (@ezemans)

    Thanks Samuel!
    How are the translation functions? could you post and example, please.

    Thread Starter ezemans

    (@ezemans)

    I did it!

    In functions.php:

    load_theme_textdomain( 'My theme name', get_template_directory().'/languages' );
    	$locale = get_locale();
    	$locale_file = get_template_directory()."/languages/$locale.php";
    	if ( is_readable($locale_file) )
    		require_once($locale_file);
    }

    Then in the templates files I used for functions: __(

    <?php the_content(__('Read more...', "My theme name")); ?>

    and for simple strings I used: _e

    <?php _e( 'Sorry, no posts matched your criteria.','My theme name' ); ?>

    Fixed! πŸ™‚

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You really don’t need all that extra stuff about $locale.php and the like. Just loading the theme textdomain is enough.

    Hi,

    Tell me please for what purpose you have changed textdomain check?

    and what is so bad if I used variant

    define( ‘TEXTDOMAIN’, get_stylesheet() );

    I’m a theme developer on the WordPress – why do I need to set for each template ‘textdomain’ instead as defined TEXTDOMAIN?

    I’m sorry but this is nonsense!

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    @cyberdeal: The text-domain has to be a plain string, and it has to be the same as the slug of the theme in order for language packs to work properly.

    Ok,

    well let’s consider another variant when using child theme

    firstly function get_stylesheet(); return values string – correct?

    define( ‘THEME_SLUG’, get_stylesheet() );
    define( ‘TEXTDOMAIN’, THEME_SLUG );
    define( ‘THEME_STYLESHEET’, get_stylesheet_directory() );
    define( ‘THEME_URI’, get_template_directory_uri() );

    function framework_languages() {
    /* child theme */
    load_theme_textdomain( TEXTDOMAIN, THEME_STYLESHEET . ‘/lang’ );
    /* parent theme */
    load_theme_textdomain( TEXTDOMAIN, THEME_DIR . ‘/lang’ );
    }

    use

    __( ‘Galleries’, TEXTDOMAIN )

    All returns string – that is incorrect?

    by the way πŸ™‚

    Notice: Undefined offset: 2 in …\wp-content\plugins\theme-check\checks\textdomain.php on line 82

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    @cyberdeal:

    Yes, that is incorrect, because the text-domain should be a plain string, not a defined one.

    Programs exist to scan code and find strings and things like that. These programs do not RUN your code, they PARSE it. It’s impossible to parse everything.

    In other words, yes, this is incorrect:
    __( 'Galleries', TEXTDOMAIN )

    It does not matter whether or not it works. What matters is that i18n parsing code expects that second parameter to be a plain string, so that it can know what the value of it is. There is no way for other code to know the value of “TEXTDOMAIN”.

    Use this instead:
    __( 'Galleries', 'theme-slug' )

    By trying to be clever, you make it difficult for other people to make their code compatible with yours. We cannot write scanning code to read every possible way that you could use defines or variables and figure out what your text-domain is. But if your text-domain is always a plain and simple string, then we don’t have to, do we? This isn’t a matter of making your code clever, it’s a matter of making it compatible and sticking to a standard.

    Edit: Additionally, child themes should only load their own textdomain. Parents can then load their own as well. Both the child and parent’s functions.php files are included, not just one or the other.

    I’m not trying to be clever, I’m trying to understand why check only quotes?!

    Your plugin check is doing just presence of quotes – it’s a stupid decision!

    If I use __ ( ‘something’, ‘”‘. TEXTDOMAIN. ‘”‘ ) checking permits it

    perhaps I should mention once again TEXTDOMAIN is a ‘theme-slug’

    <?php print ( is_string( TEXTDOMAIN ) ? 'true' : 'false' ); ?> print return “true”

    I also would like to note for the child theme and, parent theme have different language files, and they correspond to theme-slug

    eg

    …/themes/parent-theme/lang/parent-theme.pot

    …/themes/child-theme/lang/child-theme.pot

    Of course child theme has its own functions.php file

    but the hell, why should I copied all the included files from the parent theme in the child theme folder?

    only to change __ (‘Something’, ‘parent-theme’) on __ (‘something’, ‘child-theme’) ?!

    But such approach to construction of the child theme is no longer the child theme! is already an independent theme!

    by the way

    in Storefront Theme By WooThemes https://wordpress.org/themes/storefront/

    // wp-content/themes/child-theme-name/languages/it_IT.mo
    load_theme_textdomain( ‘storefront‘, get_stylesheet_directory() . ‘/languages’ );

    // wp-content/themes/storefront/languages/it_IT.mo
    load_theme_textdomain( ‘storefront’, get_template_directory() . ‘/languages’ );

    Is it the right decision?

    you claim to be so:

    // wp-content/themes/child-theme-name/languages/it_IT.mo
    load_theme_textdomain( ‘child-theme-name‘, get_stylesheet_directory() . ‘/languages’ );

    // wp-content/themes/storefront/languages/it_IT.mo
    load_theme_textdomain( ‘storefront’, get_template_directory() . ‘/languages’ );

    but your plugin allows this!

    // wp-content/themes/child-theme-name/languages/it_IT.mo
    load_theme_textdomain( ‘storefront‘, get_stylesheet_directory() . ‘/languages’ );

    Using my method through define( ‘TEXTDOMAIN’, get_stylesheet () );

    allows to me solve several problems at once, such as there is no need for duplication of the template files in the child theme, the use of ‘child-theme-slug’, etc.

    maybe to solve the problem will be enough to add an additional parameter validation is_string($domains)

    Do not you think?

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    I’m not trying to be clever, I’m trying to understand why check only quotes?!

    Your plugin check is doing just presence of quotes – it’s a stupid decision!

    It is not possible for the parser to actually *run your code*. There is no way for some other code that is simply parsing your code to know what “TEXTDOMAIN” contains.

    It is not a human being. It cannot read your code and figure it out.

    Text domains MUST be single quoted strings. Anything else is incorrect and wrong. Period.

    I think this is the wrong way to check!
    It makes me to “reinvent the wheel” πŸ™‚

    I have never in my practice are not faced with the problem that the translation does not work, you may suggest me some plugins that I could install and clearly see that my translation is not working. I must be convinced in error my way!

    Plugin Author Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    This has nothing to do with your code or whether the translation functions “work”. This has to do with other people’s code trying to read your code.

    Text domains must be plain strings. End of story. Theme-check will check for this and report errors otherwise. Eventually, failure to adhere to this check will result in a fail, which will result in your theme not being accepted on this site.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘textdomain.php’ is closed to new replies.