function.translate.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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 * Smarty plugin
15 * -------------------------------------------------------------
16 * File: function.translate.php
17 * Type: function
18 * Name: translate
19 * Purpose: translate a text
20 * Usage: e.g. {translate text="Logged in as %0% since %1%" r0="$login" r1="$logindate" [varname="loginText"]}
21 * -------------------------------------------------------------
22 */
23 function smarty_function_translate($params, \Smarty_Internal_Template $template) {
24  $variables = array();
25  foreach (array_keys($params) as $key) {
26  if (preg_match("/^r[0-9]+$/", $key)) {
27  $variables[] = $params[$key];
28  }
29  }
30  $message = ObjectFactory::getInstance('message');
31  $value = isset($params['text']) ? $message->getText($params['text'], $variables, isset($params['lang']) ? $params['lang'] : null) : "";
32  if (isset($params['varname'])) {
33  $template->assign($params['varname'], $value);
34  }
35  else {
36  echo $value;
37  }
38 }
39 ?>
$message
Predefined errors.