I'm using a custom profile template. I need display different text strings depending on browser language of user... One string for Spanish users and other string for all other users.

It seems this doesn't run:

{if $la eq 'es'}

Spanish string {else}

Catalan string {/if}

Mybe using {ts} tag? But I don't know where I should translate {ts strings}

  • are you using the snippet in .tpl file? What $l will hold? – Pradeep Nayak Jan 5 '18 at 12:11
  • Yes, I'm using the snippet in a custom profile .tpl file... And $l is an error, I mean $la (but I don't know which variable has language information, even if there are any variable to catch it in civicrm custom templates. – calbasi Jan 8 '18 at 15:40

I got it:

{if $tsLocale eq 'es_ES'}

Spanish string {else}

Catalan string {/if}

An easy way, useful to translate custom form strings used once, for example ;-)

| improve this answer | |

If you need CiviCRM to translate the string then you should use {ts}String to display{/ts}. In your case i believe the string should not translate so do not use {ts} tag.

| improve this answer | |
  • In drupal I can add a custom translatable string in a php file and system recognize it and let me translate it using string translation system. For example in a custom module. But if this can't be achieved in civicrm, I like just use a php logic process if/else to catch active language and use its related string... I don't need use general civicrm localization .po files! Just wondering what's the easy way to do it... – calbasi Jan 8 '18 at 15:52

It sounds like you're trying to translate a string, so using {ts} is the way to go. There's a nice blog post about creating local translation files that should help you prepare the Catalan one.

Three caveats:

  • You'll need to add your new string to the file that you get from CiviCRM, since it's not going to know about your customization.

  • As new versions of CiviCRM come out, you'll need to get an updated translation file and reapply your change.

  • Strictly speaking, the assumption is that the string wrapped in {ts} is US English, so you'd be normally expected to set the English one there and then translate it to Spanish and Catalan in separate local translation files, but assuming you're defaulting to Spanish on your site and not offering English, I don't think it would be a problem to have {ts} wrap a Spanish string and then set up your local translation file as Spanish-to-Catalan rather than English-to-Catalan. That means you only have to customize the Catalan file.

| improve this answer | |
  • Hi @andrew-hunt , But this is a very complex way just to translate an string in a cursom form template! It's, in fact, easier, to use some type of php logics to render a Catalan or Spanish text depending on a language variable... I mean, if I would be doing an extension / custom module, well, I think this way could be more consistent thant just a few php lines, because I can add my custom extension translation files with my custom module. But I'm just trying to add a custom footnote in a form, to be impressed when printing in paper... I've got it in Catalan, and just trying to translate – calbasi Jan 8 '18 at 15:48
  • By the way @pradeep-nayak , andrew-hunt : I like use a simple solution like this: [stackoverflow.com/a/8355986] – calbasi Jan 8 '18 at 16:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.