aboutsummaryrefslogtreecommitdiffstats
path: root/apps/shorty/lib/l10n.php
blob: 648130645a01f68141ad4ad2bc97f86455ba5d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @package shorty an ownCloud url shortener plugin
* @category internet
* @author Christian Reiner
* @copyright 2011-2012 Christian Reiner <foss@christian-reiner.info>
* @license GNU Affero General Public license (AGPL)
* @link information 
* @link repository https://svn.christian-reiner.info/svn/app/oc/shorty
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the license, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.
* If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
 * @file lib/l10n.php
 * Translation singleton
 * @author Christian Reiner
 */

/**
 * @class OC_Shorty_L10n
 * @brief Convenient translation singleton
 * @access public
 * @author Christian Reiner
 */
class OC_Shorty_L10n
{
  /**
   * @var OC_Shorty_L10n::dictionary
   * @brief An internal dictionary file filled from the translation files provided.
   * @access private
   * @author Christian Reiner
   */
  private $dictionary;

    /**
   * @var OC_Shorty_L10n::instance
   * @brief Internal singleton object
   * @access private
   * @author Christian Reiner
   */
  static private $instance=NULL;

  /**
   * @method OC_Shorty_L10n::__construct
   * @brief
   * @access private
   * @author Christian Reiner
   */
  private function __construct ( ) { $this->dictionary = new OC_L10n('shorty'); }

  /**
   * @method OC_Shorty_L10n::t
   * @brief Translates a given string into the users session language and fills any placeolders
   * @param phrase to be translated
   * @param … further arguments used as filling tokens in the tradition of printf strategies
   * @returns translated phrase or the original phrase incase no translation could be found
   * @access public
   * @author Christian Reiner
   */
  static public function t ( $phrase )
  {
    // create singleton instance, if required
    if ( ! self::$instance )
      self::$instance = new OC_Shorty_L10n ( );
    // handle different styles of how arguments can be handed over to this method
    switch ( func_num_args() )
    {
      case 1:   return self::$instance->dictionary->t ( $phrase, array() );
      case 2:   $arg = func_get_arg(1);
                if ( is_array($arg) )
                     return self::$instance->dictionary->t ( $phrase, $arg );
                else return self::$instance->dictionary->t ( $phrase, array($arg) );
      default:  $args = func_get_args();
                array_shift ( $args );
                return self::$instance->dictionary->t ( $phrase, $args );
    }
  }
} // class OC_Shorty_L10n
?>