WordPress / theme-check

Theme Check plugin
https://wordpress.org/plugins/theme-check/
341 stars 114 forks source link

Translation function calls must not contain PHP variables.... #416

Open shuvo247 opened 2 years ago

shuvo247 commented 2 years ago

RECOMMENDED: Possible variable $destination found in translation function in template-parts/common/category-bar.php. Translation function calls must not contain PHP variables, use placeholders instead. See Internationalization Guidelines (Opens in a new window).

Line 2: $destinations = get_terms(
Line 19: if ( ! empty( $destinations ) && is_array( $destinations ) ) {
Line 21: foreach ( $destinations as $destination ) { ?>
Line 24: $destination_info = get_term_meta( $destination->term_id, 'tourx_destinatio
Line 27: <a class='category-box' href='<?php echo esc_url( get_term_link( $destination ) ) ?>'>
Line 29: <img src='<?php echo $destination_info['destination_image']['url'] ?? ''?>' alt='<?php $destinat
Line 31: <?php if(!empty($destination->name)) : ?>
Line 32: <h5><?php echo __($destination->name) ?></h5>

How can I fix this issue?

carolinan commented 2 years ago

Hi! The internationalization guidelines, which are linked in the message, explains why using PHP variables or dynamic content this way does not work: https://developer.wordpress.org/apis/handbook/internationalization/internationalization-guidelines/#variables gettext can not know what "$destination->name" is.