<?php

/**
 * Translation stub
 *
 * Represents translated string. Requests for translation while instantiated.
 * Uses i18nTranslationService to provide translation while converted to string.
 *
 * @version DR1.5
 */
class i18nTranslation {



	protected $string = '';
	protected $lang = '';
	protected $translationService;



	public function __construct($string, $lang, i18nTranslationService $service) {
		$this->string = $string;
		$this->lang = $lang;
		$this->translationService = $service;
		$this->translationService->request($this->string, $this->lang);
	}



	/**
	 * Returns translated string
	 *
	 * Uses translation backend to provide translation.
	 * When no translation is available original string is returned.
	 *
	 * @return string, translation result
	 */
	public function __toString() {
		try {
			return (string)$this->translationService->getTranslation($this->string, $this->lang);
		} catch (Exception $e) {
			return $e->getMessage();
		}
	}



} // class i18nTranslation

?>