From 9946839745c5aa9e1f7a13506699e0dfcb4e03cb Mon Sep 17 00:00:00 2001 From: Mads Freek Petersen <freek@wayf.dk> Date: Wed, 23 Apr 2008 23:13:54 +0000 Subject: [PATCH] Added support for using the parameter 'replacements' when calling t(...) Makes it possible to insert 'dynamic' strings into translated strings git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@513 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/XHTML/Template.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index e1b96ab3a..6b3e4604a 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -166,7 +166,7 @@ class SimpleSAML_XHTML_Template { * @param $replacements An associative array of keys that should be replaced with values in the translated string. * @param $striptags Should HTML tags be stripped from the translation */ - private function t($tag, $fallbacktag = true, $fallbackdefault = true, $replacements = null, $striptags = false) { + private function t($tag, $fallbacktag = true, $fallbackdefault = true, $replacements = array(), $striptags = false) { if (empty($this->langtext) || !is_array($this->langtext)) { SimpleSAML_Logger::error('Template: No language text loaded. Looking up [' . $tag . ']'); @@ -183,23 +183,27 @@ class SimpleSAML_XHTML_Template { * Look up translation of tag in the selected language */ if (array_key_exists($selected_language, $this->langtext[$tag])) { - return $this->langtext[$tag][$selected_language]; + $translated = $this->langtext[$tag][$selected_language]; /** * Look up translation of tag in the default language, only if fallbackdefault = true (method parameter) */ } elseif($fallbackdefault && array_key_exists($default_language, $this->langtext[$tag])) { SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not found in language [' . $selected_language . '] using default [' . $default_language . '].'); - return $this->langtext[$tag][$default_language]; + $translated = $this->langtext[$tag][$default_language]; /** * Look up translation of tag in the base language, only if fallbackdefault = true (method parameter) */ } elseif($fallbackdefault && array_key_exists($base_language, $this->langtext[$tag])) { SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not found in language default [' . $default_language . '] using base [' . $base_language . '].'); - return $this->langtext[$tag][$base_language]; + $translated = $this->langtext[$tag][$base_language]; } + foreach ($replacements as $k => $v) { + $translated = str_replace($k, $v, $translated); + } + return $translated; } SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not translated at all.'); return $this->t_not_translated($tag, $fallbacktag); -- GitLab