From d20798186baae05d23f65c7a16b686497171772b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Mon, 28 Apr 2008 11:28:03 +0000
Subject: [PATCH] Adding functionality to template class to inline add
 translation, as well as making include language file public and possibility
 to include language files with directories from other config objects

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@526 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/XHTML/Template.php | 49 ++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index ceaa12238..e19b52bde 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -27,7 +27,7 @@ class SimpleSAML_XHTML_Template {
 	
 	public $data = null;
 
-	/*
+	/**
 	 * Constructor
 	 *
 	 * @param $configuration   Configuration object
@@ -160,6 +160,7 @@ class SimpleSAML_XHTML_Template {
 	/**
 	 * Includs a file relative to the template base directory.
 	 * This function can be used to include headers and footers etc.
+	 *
 	 */	
 	private function includeAtTemplateBase($file) {
 		$data = $this->data;
@@ -197,11 +198,11 @@ class SimpleSAML_XHTML_Template {
 	/**
 	 * Include text in the current language.
 	 *
-	 * @param $tag				A name tag of the string that should be returned.
-	 * @param $fallbacktag		If set to true and string was not found in any languages, return the tag it self.
-	 * @param $fallbackdefault 	If not found in selected language fallback to default language.
-	 * @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
+	 * @param $tag				 A name tag of the string that should be returned.
+	 * @param $fallbacktag		 If set to true and string was not found in any languages, return the tag it self.
+	 * @param $fallbackdefault 	 If not found in selected language fallback to default language.
+	 * @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 = array(), $striptags = false) {
 		
@@ -263,11 +264,43 @@ class SimpleSAML_XHTML_Template {
 	}
 	
 	
+	/**
+	 * You can include translation inline instead of putting translation
+	 * in dictionaries. This function is reccomended to only be used from dynamic
+	 * data, or when the translation is already provided from an external source, as
+	 * a database or in metadata.
+	 *
+	 * @param $tag         The tag that has a translation
+	 * @param $translation The translation array
+	 */
+	public function includeInlineTranslation($tag, array $translation) {
+		
+		if (!is_array($this->langtext)) 
+			$this->langtext = array();	
+		
+		SimpleSAML_Logger::info('Template: Adding inline language translation for tag [' . $tag . ']');
+		$this->langtext[$tag] = $translation;
+	}
+	
 	/**
 	 * Include language file from the dictionaries directory.
+	 *
+	 * @param $file         File name of dictionary to include
+	 * @param $otherConfig  Optionally provide a different configuration object than
+	 *  the one provided in the constructor to be used to find the dictionary directory.
+	 *  This enables the possiblity of combining dictionaries inside simpleSAMLphp 
+	 *  distribution with external dictionaries.
 	 */
-	private function includeLanguageFile($file) {
-		$filebase = $this->configuration->getPathValue('dictionarydir');
+	public function includeLanguageFile($file, $otherConfig = null) {
+		
+		$filebase = null;
+		if (!empty($otherConfig)) {
+			$filebase = $otherConfig->getPathValue('dictionarydir');
+		} else {
+			$filebase = $this->configuration->getPathValue('dictionarydir');
+		}
+		
+		
 		SimpleSAML_Logger::info('Template: Loading [' . $filebase . $file . ']');
 		
 		if (!file_exists($filebase . $file)) {
-- 
GitLab