| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Contains the Translation2_Admin_Decorator_Autoadd class
|
|
|
6 |
*
|
|
|
7 |
* PHP versions 4 and 5
|
|
|
8 |
*
|
|
|
9 |
* LICENSE: Redistribution and use in source and binary forms, with or without
|
|
|
10 |
* modification, are permitted provided that the following conditions are met:
|
|
|
11 |
* 1. Redistributions of source code must retain the above copyright
|
|
|
12 |
* notice, this list of conditions and the following disclaimer.
|
|
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
14 |
* notice, this list of conditions and the following disclaimer in the
|
|
|
15 |
* documentation and/or other materials provided with the distribution.
|
|
|
16 |
* 3. The name of the author may not be used to endorse or promote products
|
|
|
17 |
* derived from this software without specific prior written permission.
|
|
|
18 |
*
|
|
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
|
|
20 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
21 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
22 |
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
23 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
24 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
25 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
26 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
27 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
28 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
29 |
*
|
|
|
30 |
* @category Internationalization
|
|
|
31 |
* @package Translation2
|
|
|
32 |
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
|
|
33 |
* @author Ian Eure <ieure@php.net>
|
|
|
34 |
* @copyright 2004-2007 Lorenzo Alberton, Ian Eure
|
|
|
35 |
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
|
|
36 |
* @version CVS: $Id: Autoadd.php 305985 2010-12-05 22:55:33Z clockwerx $
|
|
|
37 |
* @link http://pear.php.net/package/Translation2
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Load Translation2_Decorator class
|
|
|
42 |
*/
|
|
|
43 |
require_once 'Translation2/Admin/Decorator.php';
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Automatically add requested strings
|
|
|
47 |
*
|
|
|
48 |
* This Decorator will add strings to a language when a request for them to be
|
|
|
49 |
* translated happens. The 'autoaddlang' option must be set to the language the
|
|
|
50 |
* strings will be added as.
|
|
|
51 |
*
|
|
|
52 |
* Example:
|
|
|
53 |
* <pre>
|
|
|
54 |
* $tr =& Translation2_Admin::factory(...);
|
|
|
55 |
* $tr->setLang('en');
|
|
|
56 |
* $tr =& $tr->getAdminDecorator('Autoadd');
|
|
|
57 |
* $tr->setOption('autoaddlang', 'en');
|
|
|
58 |
* ...
|
|
|
59 |
* $tr->get('Entirely new string', 'samplePage', 'de');
|
|
|
60 |
* </pre>
|
|
|
61 |
*
|
|
|
62 |
* 'Entirely new string' will be added to the English language table.
|
|
|
63 |
*
|
|
|
64 |
* @category Internationalization
|
|
|
65 |
* @package Translation2
|
|
|
66 |
* @author Ian Eure <ieure@php.net>
|
|
|
67 |
* @copyright 2004-2007 Ian Eure
|
|
|
68 |
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
|
|
69 |
* @link http://pear.php.net/package/Translation2
|
|
|
70 |
* @since 2.0.0beta3
|
|
|
71 |
*/
|
|
|
72 |
class Translation2_Admin_Decorator_Autoadd extends Translation2_Admin_Decorator
|
|
|
73 |
{
|
|
|
74 |
/**
|
|
|
75 |
* Language to add strings in
|
|
|
76 |
*
|
|
|
77 |
* @var string
|
|
|
78 |
*/
|
|
|
79 |
var $autoaddlang = '';
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Get a translated string
|
|
|
83 |
*
|
|
|
84 |
* @param string $stringID string ID
|
|
|
85 |
* @param string $pageID page/group ID
|
|
|
86 |
* @param string $langID language ID
|
|
|
87 |
*
|
|
|
88 |
* @return string
|
|
|
89 |
* @see Translation2::get()
|
|
|
90 |
*/
|
|
|
91 |
function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
|
|
|
92 |
{
|
|
|
93 |
$pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->translation2->currentPageID : $pageID);
|
|
|
94 |
$string = $this->translation2->get($stringID, $pageID, $langID);
|
|
|
95 |
if (PEAR::isError($string)
|
|
|
96 |
|| !strlen($string)
|
|
|
97 |
&& !empty($this->autoaddlang)
|
|
|
98 |
&& $langID == $this->autoaddlang) {
|
|
|
99 |
// Make sure we add a stub for all languages we know about.
|
|
|
100 |
$langs = array();
|
|
|
101 |
foreach ($this->translation2->getLangs('ids') as $lang) {
|
|
|
102 |
$langs[$lang] = '';
|
|
|
103 |
}
|
|
|
104 |
$langs[$this->autoaddlang] = $stringID;
|
|
|
105 |
|
|
|
106 |
// Add the string
|
|
|
107 |
$this->translation2->add($stringID, $pageID, $langs);
|
|
|
108 |
}
|
|
|
109 |
return $string;
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
?>
|