This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 9 replies, has 2 voices.

Last updated by Shekhar Bhandari 3 weeks ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
September 11, 2019 at 8:13 am

Martin Schadegg Brønniche

I am trying to: Translate the custom attributes

Link to a page where the issue can be seen: hidden link

I expected to see: The english translation

Instead, I got: the original translation

September 11, 2019 at 9:19 am
September 11, 2019 at 9:41 am #4552249

Martin Schadegg Brønniche

No then it is just removing the attributes if i disable that plugin?

September 12, 2019 at 12:31 am #4556865

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

The plugin is showing the attributes on the right hand side with better layout, when this is disabled you can view this attributes on description tab of the product, so can you check if it's showing perfectly.

Thanks

September 13, 2019 at 10:16 am #4567347

Martin Schadegg Brønniche

Where are you seeing this?
Send a screenshot please.

Looks like i'm not the first one having this problem: https://wpml.org/forums/topic/attribute-not-workingshowing-in-second-language-4/
But this didnt work.

September 13, 2019 at 10:40 am #4567579

Martin Schadegg Brønniche

This is the code snippet that gives the names of the custom attribute.
And related to your code snippet it should be correct:

							// WPML translation support
							if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
								$translation = apply_filters( 'wpml_translate_single_string', $attribute['label'], 'WordPress', 'taxonomy singular name: '. $attribute['label'] );
							    $attribute['label'] = ( ! empty( $translation ) ) ? $translation : $attribute['label'];
							}	

That is written by your support - https://wpml.org/forums/topic/product-attribute-labels-not-translated-in-french-woocommerce-php-code/

And it works on the german and spanish translation but not english.

September 16, 2019 at 1:09 am #4575551

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

I have added the screenshot.

Regarding the code, can you please let me know where it's mentioned also, how it's used in the plugin?

Look forward to your reply.

Thanks

September 19, 2019 at 7:12 am #4601859

Martin Schadegg Brønniche

The code is mentioned in the plugin "WooCommerce Show Attributes".

Its used in the foreach loop where it checks if the ICL_LANGUAGE_CODE is set. Then it should use the translated strings.

/**
	* Returns the HTML string for the product attributes.
	* This does not affect nor include attributes which are used for Variations.
	*
	* @param WC_Product_Simple|WC_Product_Variation $product Product instance. Default null to avoid errors.
	* @param string $element HTML element to wrap each attribute with, accepts span or li.
	* @param boolean $show_weight whether to show the product weight
	* @param boolean $show_dimensions whether to show the product dimensions
	* @param boolean $skip_atts whether to skip the attributes and only honor weight and dimensions
	* @param mixed $single_product true when on single product page
	*/
	public function the_attributes( $product = null, $element, $show_weight = null, $show_dimensions = null, $skip_atts = null, $single_product = null ) {

		$out = '';
		$out_middle = '';

		if ( isset( $product ) ) {
			if ( is_object( $product ) ) {

				if ( $show_weight ) {
					if ( $product->has_weight() ) {
						$weight = $product->get_weight();
						$unit = esc_attr( get_option( 'woocommerce_weight_unit' ) );
					}
				}

				if ( $show_dimensions ) {
					if ( $product->has_dimensions() ) {
						$dimensions = wc_format_dimensions( $product->get_dimensions( false ) );
					}
				}

		   		$colon = get_option( 'wcsa_remove_semicolon' ) == 'yes' ? ' ' : ': ';
				$hide_labels = get_option( 'woocommerce_show_attributes_hide_labels' );
				// check if they choose span element over li
				if ( get_option( 'woocommerce_show_attributes_span' ) == 'yes' ) {
					$element = 'span';
				}

		   		if ( ! $skip_atts ) {

					$attributes = $this->get_attributes( $product, $single_product );

					if ( ! $attributes ) {
						return;
					}

					foreach ( $attributes as $attribute ) {

						$class_string = sanitize_title( strip_tags( $attribute['value'] ) );

						$out_middle .= '<' . esc_attr( $element ) . ' class="' . esc_attr( sanitize_title( $attribute['label'] ) ) . ' ' . esc_attr( $class_string ) . '">';


						// Hide labels if they want to
						if ( 'yes' != $hide_labels ) {
								
							// PolyLang translation support
							if ( function_exists( 'pll__' ) ) {
								$translation = pll__( $attribute['label'] );
								$attribute['label'] = ( ! empty( $translation ) ) ? $translation : $attribute['label'];
							}
							// WPML translation support
							if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
								$translation = apply_filters( 'wpml_translate_single_string', $attribute['label'], 'WordPress', 'taxonomy singular name: '. $attribute['label'] );
							    $attribute['label'] = ( ! empty( $translation ) ) ? $translation : $attribute['label'];
							}										

							$out_middle .= '<span class="attribute-label"><span class="attribute-label-text">' . sprintf( __( '%s', 'woocommerce-show-attributes' ), esc_html( $attribute['label'] ) ) . '</span>' . $colon . ' </span> ';
							
						}
							
						$out_middle .= '<span class="attribute-value">';
						$out_middle .= $attribute['value'];
						$out_middle .= '</span></' . esc_attr( $element ) . '>';

						if ('span' == $element) {
							$out_middle .= '<br />';
						}
					

					} // ends foreach attribute
				}

				// Add weight and dimensions if they opted in

				if ( ! empty( $weight ) ) {
					$unit = empty( $unit ) ? '' : $unit;
					// weight
					$out_middle .= '<' . esc_attr( $element ) . ' class="show-attributes-weight">';
					// Hide labels if they want to
					if ( $hide_labels != 'yes' ) {
						$out_middle .= '<span class="attribute-label">' . __( 'Weight', 'woocommerce-show-attributes' ) . $colon . ' </span> ';
					}
					$out_middle .= '<span class="attribute-value">' . esc_html( $weight ) . ' ' . esc_html( $unit ) . ' </span></' . esc_attr( $element ) . '>';
					if ( 'span' == $element ) {
						$out_middle .= '<br />';
					}
				}

				if ( ! empty( $dimensions ) ) {
					// dimensions
					$out_middle .= '<' . esc_attr( $element ) . ' class="show-attributes-dimensions">';
					// Hide labels if they want to
					if ( $hide_labels != 'yes' ) {
						$out_middle .= '<span class="attribute-label">' . __( 'Dimensions', 'woocommerce-show-attributes' ) . $colon . ' </span> ';
					}
					$out_middle .= '<span class="attribute-value">' . esc_html( $dimensions ) . '</span></' . esc_attr( $element ) . '>';
					if ('span' == $element) {
						$out_middle .= '<br />';
					}
				}

				if ( $out_middle ) {
					$out = ('li' == $element) ? '<ul ' : '<span ';
					$out .= 'class="custom-attributes">' . $out_middle;
					$out .= ('li' == $element) ? '</ul>' : '</span>';
				}

		

			}
		}
		return $out;
	}
September 19, 2019 at 10:11 am #4603413

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

It looks like a compatibility issue with the theme. To debug compatibility issue quickly, it will be best to test the issue on a fresh new Installation, being so I would need your little help to pinpoint the issue further.

I have created a fresh new WordPress Installed test site here, hidden link you can click on the link to login.

Could you please use the same settings there and see if you can replicate the issue? Please don't use personal information on the site as it's a test site, I recommend using some dummy data.

This will help us to figure out if this is actually a compatibility issue or a site-specific issue.

Look forward to your reply.

Thanks

September 20, 2019 at 12:19 pm #4612011

Martin Schadegg Brønniche

So you want me to create the whole website again???????

September 23, 2019 at 2:27 am #4619791

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

No, there is no need to create the whole site again. Just add the WooCommerce Attributes plugin along with basic WPML setup and use some demo content, this will help us to debug this further.

Look forward to your reply.

Thanks

The topic ‘[Closed] Custom product attribute is translated to german but not english’ is closed to new replies.