function.translate.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
13 /**
14  * Translate a static text.
15  *
16  * Example:
17  * @code
18  * {translate text="Logged in as %0% since %1%" r0=$login r1=$logindate}
19  * @endcode
20  *
21  * @param $params Array with keys:
22  * - text: The text to translate
23  * - r0, r1, ...: Values for text variables (%0%, %1%, ...)
24  * - lang: The language to translate to
25  * @param $template Smarty_Internal_Template
26  * @return String
27  */
28 function smarty_function_translate($params, Smarty_Internal_Template $template) {
29  $variables = [];
30  foreach (array_keys($params) as $key) {
31  if (preg_match("/^r[0-9]+$/", $key)) {
32  $variables[] = $params[$key];
33  }
34  }
35  $message = ObjectFactory::getInstance('message');
36  $value = isset($params['text']) ? $message->getText($params['text'], $variables, isset($params['lang']) ? $params['lang'] : null) : "";
37  echo $value;
38 }
39 ?>
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...