Merge pull request #21945 from masetto/profile-data-attribute
[civicrm-core.git] / CRM / Core / Smarty / plugins / block.localize.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * Smarty block function for multilingualizing upgrade SQL queries.
20 * The string passed in $text is repeated locale-number times, with the
21 * param field (if provided) appended with a different locale every time.
22 *
6a0b768e
TO
23 * @param array $params
24 * Template call's parameters.
25 * @param string $text
26 * {ts} block contents from the template.
16b10e64 27 * @param CRM_Core_Smarty $smarty
6a0b768e 28 * The Smarty object.
6a488035 29 *
a6c01b45 30 * @return string
353ffa53 31 * multilingualized query
6a488035
TO
32 */
33function smarty_block_localize($params, $text, &$smarty) {
1832ba99 34 if (!array_key_exists('multilingual', $smarty->_tpl_vars) || !$smarty->_tpl_vars['multilingual']) {
6a488035
TO
35 return $text;
36 }
37
be2fb01f 38 $lines = [];
6a488035
TO
39 foreach ($smarty->_tpl_vars['locales'] as $locale) {
40 $line = $text;
0efafdb0 41 if (isset($params['field'])) {
6a488035
TO
42 $fields = explode(',', $params['field']);
43 foreach ($fields as $field) {
44 $field = trim($field);
45 $line = preg_replace('/\b' . preg_quote($field) . '\b/', "{$field}_{$locale}", $line);
46 }
47 }
48 $lines[] = $line;
49 }
50
51 return implode(', ', $lines);
52}