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

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

Design: Linkfarben, Footerrelationslinks, Einblendlogik von Relationen.

  • menu.php: Linkdetail-Getter umgeformt
  • template.php: Mehr Daten in bodyclasses und javascriptconfig durchgeben
  • a.go-Doppelfeile, mal testweise per content-before umgesetzt
  • Relationale Navigation huebscher Formatiert, nach dem Vorschlag von Intsar vom 23.04.2012
  • Inhalts-Linkfarben mit dunkler Linkfarbe
  • menu.js: Beam nur anzeigen wenn im Inhalt, ebenso mit Relationslinks (template.php)
  • Property svn:keywords set to Id
File size: 5.5 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         * @param lang  The wanted target language (string like 'de' or 'en'). Leave empty for object default lang ($this->lang)
33         * @returns Found string in current locale ($lang)
34         **/
35        function _($str_id, $lang=null) {
36                $lang = ($lang && isset(self::$order[$lang])) ? $lang : $this->lang;
37                if(!isset(self::$msg[$str_id])) {
38                        return "&lt;$str_id&gt;"; // error; mediawiki style
39                } else {
40                        if(is_array(self::$msg[$str_id])) {
41                                return self::$msg[$str_id][ self::$order[$lang] ];
42                        } else
43                                return self::$msg[$str_id];
44                }
45        }
46       
47        /**
48         * Returns a function which prints the output of _. Usage:
49         *
50         * $msg = new t29Messages("foo");
51         * print $msg->_("foobar");              // ordinary long version
52         * $_ = $msg->get_shorthand_printer();
53         * $_("foobar");                         // same but shorter
54         **/
55        function get_shorthand_printer() {
56                $t = $this;
57                return function($str,$lang=null)use($t) { print $t->_($str,$lang); };
58        }
59
60        /// same like get_shorthand_printer but return instead of print
61        function get_shorthand_returner() {
62                $t = $this;
63                return function($str,$lang=null)use($t) { return $t->_($str,$lang); };
64        }
65
66        /**
67         * Returns the $msg array as well as the order array encoded as JSON.
68         * The output will look like '{order:{de:0,en:1},msg:{'foo':['bar,'baz']}}'.
69         * A given $filter_regexp will be run on the msg keys and hence give
70         * out only matching entries. Example: $filter_regexp = "/^js-/"
71         * would filter out all JavaScript related entries.
72         **/
73        static function create_json($filter_regexp=false) {
74                $msg = $filter_regexp ? array_intersect_key(self::$msg,
75                                array_flip(preg_grep($filter_regexp, array_keys(self::$msg)))
76                                ) : self::$msg;
77                return json_encode(array(
78                        'order' => self::$order,
79                        'msg'   => $msg
80                ));
81        }
82
83        /**
84         * The Messages array maps a message id (string) to the message text
85         * (string or numeric array). If the message value is an array, it will be
86         * interpreted as multi language string, whereas the mapping from language
87         * to index is supposed to be done via the $order array (see above).
88         **/
89        public static $msg = array(
90                'html-title'             => 'technikum29',
91                'head-h1-title'          => array('Zur technikum29 Startseite', 'Go to technikum29 homepage'),
92                'head-h1'                => 'technikum29',
93                'homepage-pagename'      => 'startseite', # seiten_id der startseite
94
95                'sidebar-h2-tour'        => array('Museumstour', 'Museum Tour'),
96                'sidebar-h2-mainnav'     => array('Hauptnavigation', 'Main Navigation'),
97                'sidebar-h2-lang'        => array('Sprachauswahl', 'Language'),
98
99                'topnav-interlang-title' => array('Die Seite "%s" auf Deutsch lesen', 'Read the page "%s" in English'),
100                'topnav-interlang-active' => array('Sie betrachten gerade die Seite "%s" auf Deutsch', 'You currently read the page "%s" in English'),
101                'topnav-interlang-nonexistent' => array('Diese Seite steht auf Deutsch nicht zur Verfügung', 'This page is not available in English'),
102                'topnav-search-label'    => array('Suchen', 'Search'),
103                'topnav-search-page'     => array('/suche.php', '/search.php'),
104                'opensearch-desc'        => array('technikum29 (de)', 'technikum29 (en)'),
105
106                'js-menu-collapse-out'   => array('Mehr Details', 'Expand menu'),
107                'js-menu-collapse-in'    => array('Weniger Details', 'Fold menu'),
108                'js-menu-scroll-show'    => array('Menü einblenden', 'Show menu'),
109                'js-menu-scroll-hide'    => array('Menü ausblenden', 'Hide menu'),
110
111                'footer-copyright-tag'   => '&copy; 2003-2012 technikum29.',
112                'footer-legal-link'      => array('Impressum und Kontakt', 'Legal notices'),
113                'footer-legal-file'      => array('/impressum.php', '/contact.php'),
114               
115                'nav-rel-prev'           => array('vorherige Seite', 'previous page'),
116                'nav-rel-next'           => array('nächste Seite', 'next page'),
117                'nav-rel-start'          => array('Starte Führrung', 'Start guided tour'),
118               
119                'head-rel-first'         => array('Deutscher Start', 'English start'),
120                'head-rel-prev'          => array('Zur vorherigen Seite (%s)', 'Previous Page (%s)'),
121                'head-rel-next'          => array('Zur folgenden Seite (%s)', 'Next Page (%s)'),
122                'head-rel-interlang'     => array('Deutsche Version dieser Seite (%s)', 'English Version of this page (%s)'),
123               
124                // used in /shared/js/modules/heading_links.js
125                'js-heading-links'       => array("Direktlink zu diesem Abschnitt", "Link to this section"),
126                // used in /shared/js/modules/img_license.js
127                'js-img-license'         => array(
128                                                                                '&copy; technikum29. <a href="/de-v6/impressum.php#image-copyright">Lizenzbestimmungen</a>',
129                                                                                '&copy; technikum29. <a href="/en-v6/contact.php#image-copyright">Licensing terms</a>',
130                                                                        ),
131        );
132}
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