CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Token translation
Pages: [1]

Author Topic: Token translation  (Read 2401 times)

mkalbere

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
Token translation
August 19, 2011, 03:07:23 am
Hello,
It seems that tokens are not translated when using "pdf letter" or mailing.  Specially  {contact.country} which systematicaly output the country name in english.
How could I acheive this ?
Thanks,
Marc

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
Re: Token translation
November 24, 2012, 01:48:17 pm
This is still an issue in 4.1 and 4.2.

Did you find any way to handle this?

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
Re: Token translation
November 26, 2012, 07:24:08 am
For archiving, if someone is interested.
Although I think it should be in core and not in a drupal module: Country + State should be translated in a token.

This is the drupal custom_token.module
I have limited it to Create Label, but can easily be extended to other contexts.

Code: [Select]
function custom_tokens_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null){
        civicrm_initialize( );
        require_once 'CRM/Core/PseudoConstant.php';

        if  ($context == "CRM_Contact_Form_Task_Label")
        {
                foreach ($cids as $cid)
                {
                        if (isset($values[$cid]["country_id"])){
                                $values[$cid]["country"] = CRM_Core_PseudoConstant::country($values[$cid]["country_id"]);
                               
                        }

                }
        }
}

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Token translation
November 26, 2012, 09:28:53 am
How about submitting a patch for CiviCRM core?
Try asking your question on the new CiviCRM help site.

CatorgHans

  • I post frequently
  • ***
  • Posts: 157
  • Karma: 5
  • CiviCRM version: 4.4
  • CMS version: drupal
Re: Token translation
November 27, 2012, 01:39:07 am
yeah, good point.

My question is: is there a reason why these tokens are not translated in core, or is it just never build?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Token translation
November 27, 2012, 10:54:08 am
My guess would be the latter. And I think switching the code to using a pseudoconstant instead of a left join will fix it.
Try asking your question on the new CiviCRM help site.

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Token translation
November 27, 2012, 11:54:18 am
I traced it to CRM/Utils/Token.php, getTokenDetails(), but from there it calls:

Code: [Select]

    $query = new CRM_Contact_BAO_Query($params, $returnProperties);
    $details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);

Then it goes into CRM/Contact/BAO/Query.php, and in there, it does a LEFT JOIN on civicrm_address.

How to change that for a PseudoConstant?
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Token translation
November 27, 2012, 10:11:37 pm

yeah. seems like tokens do bypass the translation engine  :(

you want the query to retrive the country ID for efficiency purposes, so i suspect u want to do the translation in the process of assigning the token a value.

I think state and countries are the few entries where we do the translation post-database. Most of the values in the database should be in a translated state. So maybe special case these two fields?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Token translation
May 24, 2013, 10:27:08 am
I hate to complicate an already very complicated area, but....

Some of my clients want their addresses to be English or French depending on the recipient, not the language of the current user. This is particularly the case when printing a PDF letter or running labels. They operate their website in English and French so the CiviCRM instance is multilingual.

What would be the best way to handle something like this? Store language preference by contact, then use that to determine the language to use to render the province field?
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Token translation

This forum was archived on 2017-11-26.