41 private $translations = [];
50 if (strlen($language) > 0) {
51 $this->language = $language;
53 else if (isset($_SERVER[
'HTTP_ACCEPT_LANGUAGE'])) {
54 $this->language = $_SERVER[
'HTTP_ACCEPT_LANGUAGE'];
61 public function getText($message, $parameters=
null, $lang=
'') {
63 $lang = strlen($lang) == 0 ? $this->language : $lang;
64 $translations = $this->getTranslations($lang);
65 $localizedMessage = $message;
66 if (isset($translations[$message]) && strlen($translations[$message]) > 0) {
67 $localizedMessage = $translations[$message];
71 preg_match_all(
"/%([0-9]+)%/", $localizedMessage, $matches);
72 $matches = $matches[1];
73 for ($i=0, $count=
sizeof($matches); $i<$count; $i++) {
74 $matches[$i] =
'/\%'.$matches[$i].
'\%/';
77 if (
sizeof($matches) > 0 && is_array($parameters)) {
78 $localizedMessage = preg_replace($matches, $parameters, $localizedMessage);
80 return $localizedMessage;
88 $translations = $this->getTranslations($lang);
97 private function getTranslations($lang) {
98 if (!isset($this->translations[$lang])) {
99 $messageFile = $this->localeDir.
"/messages_".$lang.
".php";
100 if (file_exists($messageFile)) {
101 require_once($messageFile);
103 $this->translations[$lang] = ${
"messages_$lang"};
106 $this->translations[$lang] = [];
109 return $this->translations[$lang];
__construct($localeDir, $language='')
Constructor.
getText($message, $parameters=null, $lang='')
FileUtil provides basic support for file functionality like HTTP file upload.
static realpath($path)
Realpath function that also works for non existing paths code from http://www.php....
Message is used to get localized messages to be used in the user interface.
FileMessage retrieves localized messages from files, that are stored in the localization directory.