File modules/cms/base/Language.class.php
Last commit: Sun Nov 1 00:36:50 2020 +0100 Jan Dankert Refactoring: Only using the configuration object.
1 <?php 2 // OpenRat Content Management System 3 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 namespace cms\base; 20 21 use logger\Logger; 22 use util\text\variables\VariableResolver; 23 24 class Language 25 { 26 /** 27 * Diese Funktion stellt ein Wort in der eingestellten 28 * Sprache zur Verfuegung. 29 * 30 * @var String Name der Sprachvariablen 31 * @var Array Liste (Assoziatives Array) von Variablen 32 * 33 * @package openrat.functions 34 */ 35 public static function lang($textVar, $vars = array()) 36 { 37 $conf = Configuration::rawConfig(); 38 $lang = $conf['language']; 39 40 $text = strtoupper($textVar); 41 42 // Abfrage, ob Textvariable vorhanden ist 43 if (isset($lang[$text])) { 44 $text = $lang[$text]; 45 46 // Fill in variables 47 if ($vars) { 48 $resolver = new VariableResolver(); 49 50 // Resolve variable 51 $resolver->addDefaultResolver(function ($var) use ($vars) { 52 return @$vars[$var]; 53 }); 54 55 $text = $resolver->resolveVariables($text); 56 } 57 58 return $text; 59 } 60 61 if ( DEVELOPMENT ) { 62 Logger::warn('Message-Key not found: ' . $textVar); 63 return '??' . $textVar . '??'; 64 } 65 66 // Wenn Textvariable nicht vorhanden ist, dann als letzten Ausweg nur den Variablennamen zurueckgeben 67 return $textVar; 68 } 69 }
Downloadmodules/cms/base/Language.class.php
History Sun, 1 Nov 2020 00:36:50 +0100 Jan Dankert Refactoring: Only using the configuration object. Sat, 26 Sep 2020 10:32:02 +0200 Jan Dankert Refactoring: No global $conf array any more. Sat, 26 Sep 2020 04:26:55 +0200 Jan Dankert Refactoring: read configuration values with a class. Sat, 26 Sep 2020 04:03:53 +0200 Jan Dankert Refactoring: read language keys with a class. Sat, 26 Sep 2020 03:03:47 +0200 Jan Dankert Refactoring: less global functions. Sat, 26 Sep 2020 01:41:20 +0200 Jan Dankert Refactoring: Removing old require.php files. With class autoloading, they are not necessary any more.