source: t29-www/lib/messages.php @ 273

Last change on this file since 273 was 273, checked in by sven, 12 years ago

Backend modifications:

  • ressourceloader.php can generate URLs for its own system and can instanciate an RL instance by grabbing the config from loader.php
  • template.php requests RessourceLoader for URLs (so debugging URLs can directly be injected in the template)
  • template.php and cache.php can handle header/footer seperatedly in two cache files for dynamical page content
  • suche.php and search.php as the search framework basis; they can already print a XML opensarch description.
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1<?php
2/**
3 * t29v6 Message subsystem.
4 *
5 **/
6
7// You can run this script to get all messages as JSON.
8// See also /shared/js/modules/msg.js and js.php.
9if(realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) {
10        header('Content-Type: application/json');
11        if(isset($_GET['pre'])) echo $_GET['pre'];
12        echo t29Messages::create_json();
13        if(isset($_GET['post'])) echo ";\n".$_GET['post'];
14}
15
16class t29Messages {
17        /// when instanciated, stores the language to lookup for _()
18        public $lang;
19
20        /// The order of array elements in $msg. This array maps
21        /// $lang shortstring to array index position.
22        public static $order = array('de' => 0, 'en' => 1);
23       
24        function __construct($lang) {
25                $this->lang = $lang;
26        }
27
28        /**
29         * The translate function, shorthand like the gettext shorthand.
30         * There's actually no long method name version :D
31         * @param str_id  Some key from the $msg array
32         * @returns Found string in current locale ($lang)
33         **/
34        function _($str_id) {
35                if(!isset(self::$msg[$str_id])) {
36                        return "&lt;$str_id&gt;"; // error; mediawiki style
37                } else {
38                        if(is_array(self::$msg[$str_id])) {
39                                return self::$msg[$str_id][ self::$order[$this->lang] ];
40                        } else
41                                return self::$msg[$str_id];
42                }
43        }
44       
45        /**
46         * Returns a function which prints the output of _. Usage:
47         *
48         * $msg = new t29Messages("foo");
49         * print $msg->_("foobar");              // ordinary long version
50         * $_ = $msg->get_shorthand_printer();
51         * $_("foobar");                         // same but shorter
52         **/
53        function get_shorthand_printer() {
54                $t = $this;
55                return function($str)use($t) { print $t->_($str); };
56        }
57
58        /// same like get_shorthand_printer but return instead of print
59        function get_shorthand_returner() {
60                $t = $this;
61                return function($str)use($t) { return $t->_($str); };
62        }
63
64        /**
65         * Returns the $msg array as well as the order array encoded as JSON.
66         * The output will look like '{order:{de:0,en:1},msg:{'foo':['bar,'baz']}}'.
67         * A given $filter_regexp will be run on the msg keys and hence give
68         * out only matching entries. Example: $filter_regexp = "/^js-/"
69         * would filter out all JavaScript related entries.
70         **/
71        static function create_json($filter_regexp=false) {
72                $msg = $filter_regexp ? array_intersect_key(self::$msg,
73                                array_flip(preg_grep($filter_regexp, array_keys(self::$msg)))
74                                ) : self::$msg;
75                return json_encode(array(
76                        'order' => self::$order,
77                        'msg'   => $msg
78                ));
79        }
80
81        /**
82         * The Messages array maps a message id (string) to the message text
83         * (string or numeric array). If the message value is an array, it will be
84         * interpreted as multi language string, whereas the mapping from language
85         * to index is supposed to be done via the $order array (see above).
86         **/
87        public static $msg = array(
88                'html-title'             => 'technikum29',
89                'head-h1-title'          => array('Zur technikum29 Startseite', 'Go to technikum29 homepage'),
90                'head-h1'                => 'technikum29',
91
92                'sidebar-h2-tour'        => array('Museumstour', 'Museum Tour'),
93                'sidebar-h2-mainnav'     => array('Hauptnavigation', 'Main Navigation'),
94                'sidebar-h2-lang'        => array('Sprachauswahl', 'Language'),
95
96                'topnav-interlang-title' => array('Read this page (%s) in English', 'Diese Seite (%s) auf Deutsch lesen'),
97                'topnav-search-label'    => array('Suchen', 'Search'),
98                'topnav-search-page'     => array('/suche.php', '/search.php'),
99                'opensearch-desc'        => array('technikum29 (de)', 'technikum29 (en)'),
100
101                'js-menu-collapse-out'   => array('Menü ausklappen', 'Expand menu'),
102                'js-menu-collapse-in'    => array('Menü einklappen', 'Fold menu'),
103                'js-menu-scroll-show'    => array('Menü einblenden', 'Show menu'),
104                'js-menu-scroll-hide'    => array('Menü ausblenden', 'Hide menu'),
105
106                'footer-copyright-tag'   => '&copy; 2003-2012 technikum29.',
107                'footer-legal-link'      => array('Impressum und Kontakt', 'Legal notices'),
108                'footer-legal-file'      => array('/impressum.php', '/contact.php'),
109               
110                'nav-rel-prev'           => array('vorherige Seite', 'previous page'),
111                'nav-rel-next'           => array('nächste Seite', 'next page'),
112                'nav-rel-start'          => array('Starte Führrung', 'Start guided tour'),
113               
114                'head-rel-first'         => array('Deutscher Start', 'English start'),
115                'head-rel-prev'          => array('Zur vorherigen Seite (%s)', 'Previous Page (%s)'),
116                'head-rel-next'          => array('Zur folgenden Seite (%s)', 'Next Page (%s)'),
117                'head-rel-interlang'     => array('Englische Version dieser Seite (%s)', 'Deutsche Version dieser Seite (%s)'),
118               
119                // used in /shared/js/modules/heading_links.js
120                'js-heading-links'       => array("Direktlink zu diesem Abschnitt", "Link to this section"),
121                // used in /shared/js/modules/img_license.js
122                'js-img-license'         => array(
123                                                                                '&copy; technikum29. <a href="/de-v6/impressum.php#image-copyright">Lizenzbestimmungen</a>',
124                                                                                '&copy; technikum29. <a href="/en-v6/contact.php#image-copyright">Licensing terms</a>',
125                                                                        ),
126        );
127}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License