0

I am conditionally concatenating a very long string onto another very long string. Then I am returning it as the argument to another function. I think I should translate the strings individually first, and then concatenate the result. However, I know in general strings should be concatenated first, and then translated, as this will make a better translation. But the conditional prevents that, and maybe it doesn't matter anyway if both strings are 3+ sentences long. Also I would normally use sprintf with the second string represented as a placeholder, but it's too long for that.

function get_string(){

     $str = __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lacinia sagittis 
     elit, ut vehicula sapien pulvinar id. Phasellus blandit non sapien non efficitur. Etiam 
     lacinia mi ac aliquam lacinia. Pellentesque blandit, lectus sit amet ultricies consequat, 
     enim augue fermentum massa, sed tempor elit arcu nec turpis.', 'text-domain' ); 


  if ( is_page_template( 'page_templates/abcd' ){

    $str .= __('Nam mattis bibendum mauris nec commodo. Nunc posuere, ex sed auctor ornare, odio 
    urna accumsan nisi, ac luctus arcu nisl lobortis mauris. Etiam volutpat sagittis felis,vitae 
    efficitur elit vehicula id. Vivamus faucibus risus risus, quis pretium nibh semper vitae. 
    Sed vehicula ex velit, auctor hendrerit risus bibendum eget. Nulla sit amet efficitur ex.','text- domain');

  }
  return $str;
}

Is this correct?

2
  • If you really think that they might need to be translated together, then instead of concatenating, just switch between two separate strings, repeating the text from the first. May 11 '20 at 8:35
  • @JacobPeattie I hadn't thought of just repeating the string. That seems like the right way to go, thanks.
    – Harrison
    May 11 '20 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.