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

Last change on this file since 1419 was 1419, checked in by sven, 6 years ago

Jahreszahl in der Fußzeile: 2017 -> 2018.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1<?php
2/**
3 * t29v6 Message subsystem.
4 * now with instanciated message overwriting.
5 *
6 **/
7
8// You can run this script to get all messages as JSON.
9// See also /shared/js/modules/msg.js and js.php.
10if(realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) {
11        header('Content-Type: application/json');
12        if(isset($_GET['pre'])) echo $_GET['pre'];
13        echo t29Messages::create_json();
14        if(isset($_GET['post'])) echo ";\n".$_GET['post'];
15}
16
17class t29Messages {
18        /// when instanciated, stores the language to lookup for _()
19        public $lang;
20       
21        /// The order of array elements in $msg. This array maps
22        /// $lang shortstring to array index position.
23        public static $order = array('de' => 0, 'en' => 1);
24       
25        function __construct($lang) {
26                $this->lang = $lang;
27        }
28
29        /**
30         * Add new messages to the local overwrite array.
31         **/
32        function set($str_id, $content) {
33                $this->local_msg[$str_id] = $content;
34        }
35
36        /**
37         * The translate function, shorthand like the gettext shorthand.
38         * There's actually no long method name version :D
39         * @param str_id  Some key from the $msg array
40         * @param lang  The wanted target language (string like 'de' or 'en'). Leave empty for object default lang ($this->lang)
41         * @returns Found string in current locale ($lang)
42         **/
43        function _($str_id, $lang=null) {
44                // local overwrites come first
45                if(isset($this->local_msg[$str_id]))
46                        return $this->local_msg[$str_id];
47       
48                $lang = ($lang && isset(self::$order[$lang])) ? $lang : $this->lang;
49                if(!isset(self::$msg[$str_id])) {
50                        return "&lt;$str_id&gt;"; // error; mediawiki style
51                } else {
52                        if(is_array(self::$msg[$str_id])) {
53                                return self::$msg[$str_id][ self::$order[$lang] ];
54                        } else
55                                return self::$msg[$str_id];
56                }
57        }
58       
59        /**
60         * Returns a function which prints the output of _. Usage:
61         *
62         * $msg = new t29Messages("foo");
63         * print $msg->_("foobar");              // ordinary long version
64         * $_ = $msg->get_shorthand_printer();
65         * $_("foobar");                         // same but shorter
66         **/
67        function get_shorthand_printer() {
68                $t = $this;
69                return function($str,$lang=null)use($t) { print $t->_($str,$lang); };
70        }
71
72        /// same like get_shorthand_printer but return instead of print
73        function get_shorthand_returner() {
74                $t = $this;
75                return function($str,$lang=null)use($t) { return $t->_($str,$lang); };
76        }
77
78        /**
79         * Returns the $msg array as well as the order array encoded as JSON.
80         * The output will look like '{order:{de:0,en:1},msg:{'foo':['bar,'baz']}}'.
81         * A given $filter_regexp will be run on the msg keys and hence give
82         * out only matching entries. Example: $filter_regexp = "/^js-/"
83         * would filter out all JavaScript related entries.
84         * This method doesn't consider the $local_msg's.
85         **/
86        static function create_json($filter_regexp=false) {
87                $msg = $filter_regexp ? array_intersect_key(self::$msg,
88                                array_flip(preg_grep($filter_regexp, array_keys(self::$msg)))
89                                ) : self::$msg;
90                return json_encode(array(
91                        'order' => self::$order,
92                        'msg'   => $msg
93                ));
94        }
95
96        /**
97         * Since the static messages are considered as `const`, any changes/overwrites
98         * will be applied to the instanciated object. Use the gettext for correct
99         * handling.
100         * This array simply maps message id to string without language handling since
101         * the instances don't know languages.
102         */
103        public $local_msg = array();
104
105        /**
106         * The Messages array maps a message id (string) to the message text
107         * (string or numeric array). If the message value is an array, it will be
108         * interpreted as multi language string, whereas the mapping from language
109         * to index is supposed to be done via the $order array (see above).
110         **/
111        public static $msg = array(
112                'html-title'             => 'technikum29',
113                'head-h1-title'          => array('Zur technikum29 Startseite', 'Go to technikum29 homepage'),
114                'head-h1'                => 'technikum29',
115                'homepage-pagename'      => 'startseite', # seiten_id der startseite
116
117                'sidebar-h2-tour'        => array('Museumstour', 'Museum Tour'),
118                'sidebar-h2-mainnav'     => array('Hauptnavigation', 'Main Navigation'),
119                'sidebar-h2-lang'        => array('Sprachauswahl', 'Language'),
120
121                'topnav-interlang-title' => array('Die Seite "%s" auf Deutsch lesen', 'Read the page "%s" in English'),
122                'topnav-interlang-active' => array('Sie betrachten gerade die Seite "%s" auf Deutsch', 'You currently read the page "%s" in English'),
123                'topnav-interlang-nonexistent' => array('Diese Seite steht auf Deutsch nicht zur Verfügung', 'This page is not available in English'),
124                'topnav-interlang-nonexistent-page' => '/en/no-translation.php',
125                'topnav-search-label'    => array('Suchen', 'Search'),
126                'topnav-search-page'     => array('/suche.php', '/search.php'),
127                'opensearch-desc'        => array('technikum29 (de)', 'technikum29 (en)'),
128
129                'js-menu-collapse-out'   => array('Mehr Details', 'Expand menu'),
130                'js-menu-collapse-in'    => array('Weniger Details', 'Fold menu'),
131                'js-menu-scroll-show'    => array('Menü einblenden', 'Show menu'),
132                'js-menu-scroll-hide'    => array('Menü ausblenden', 'Hide menu'),
133
134                'footer-copyright-tag'   => '&copy; 2003-2018 technikum29.',
135                'footer-legal-link'      => array('Impressum und Kontakt', 'Legal notices'),
136                'footer-legal-file'      => array('/impressum.php', '/contact.php'),
137                'footer-legacy-text'     => array('&copy; 2003-2018 technikum29. Alle Bilder und Fotografien sind kopierrechtlich geschützt, siehe <a href="/de/impressum.php" class="go">Impressum</a>',
138                                                  '&copy; 2003-2018 technikum29. You must not use contents and photographies without the permission of the owner. <a href="/en/contact.php" class="go">Legal Information</a>.'),
139                'footer-sitemap-text'    => 'Sitemap',
140                'footer-sitemap-link'    => array('/de/sitemap.php', '/en/sitemap.php'),
141                'footer-haus-text'       => array('Das technikum29 ist ein <u>interaktives Museum</u> im <u>Rhein-Main-Gebiet</u> (nahe Frankfurt). Informationen zu <u>Führungen</u> und <u>Öffnungszeiten</u> erfahren Sie auf der <u>Startseite</u>',
142                                                'The technikum29 is a <u>living computer museum</u> located in <u>Germany, near Frankfurt</u>. We regularly offer <u>guided tours</u>.'),
143                'footer-haus-link'       => array('/de/', '/en/'),
144                'footer-image-copyright-text' => array('Viele Bilder können unter einer <u>CreativeCommons-Lizenz</u> verwendet werden. <u>Erkundigen Sie sich</u>.',
145                                                'Except where other noted, pictures on this site are licensed under a <u>Creative Commons License</u>.'),
146               
147                'nav-hierarchy-current'  => array('Aktuelle Seite', 'Current page'),
148                'nav-hierarchy-ancestor' => array('Übergeordnete Kategorie der aktuellen Seite', 'Parental category of current page'),
149                'nav-rel-prev'           => array('vorherige Seite', 'previous page'),
150                'nav-rel-next'           => array('nächste Seite', 'next page'),
151                'nav-rel-start'          => array('Starte Führrung', 'Start guided tour'),
152               
153                'head-rel-first'         => array('Deutscher Start', 'English start'),
154                'head-rel-prev'          => array('Zur vorherigen Seite (%s)', 'Previous Page (%s)'),
155                'head-rel-next'          => array('Zur folgenden Seite (%s)', 'Next Page (%s)'),
156                 //'head-rel-interlang'     => array('Deutsche Version dieser Seite (%s)', 'English Version of this page (%s)'),
157               
158                // used in /shared/js/modules/heading_links.js
159                'js-heading-links'       => array("Direktlink zu diesem Abschnitt", "Link to this section"),
160                // used in /shared/js/modules/img_license.js
161                'js-img-license'         => array(
162                                                                                '&copy; technikum29. <a href="/de/impressum.php#image-copyright">Lizenzbestimmungen</a>',
163                                                                                '&copy; technikum29. <a href="/en/contact.php#image-copyright">Licensing terms</a>',
164                                                                        ),
165                                                                       
166                // piwik logging settings
167                'js-piwik-noscript-imgsrc' => '/logs/piwik/piwik.php?idsite=1',
168                'js-piwik-url-prefix' => '/logs/piwik/',
169                'js-piwik-siteid' => '1',
170               
171                // interlang.js
172                'js-interlang-notify-heading' => array("This page is also avaliable in English", "Diese Website gibt es auch auf Deutsch"),
173                'js-interlang-notify-text' => array("Do you want to switch to the English version <i>%s</i>?", "Möchtest du die deutschsprachige Seite <i>%s</i> lesen?"),
174
175                // RSS-feed, in /lib/news.php verwendet
176                'rss-title' => array('technikum29 Computer Museum - Was gibt es Neues?','technikum29 Computer Museum - What\'s new?'),
177                'rss-description' => array('Neuste Geräte und Erweiterungen im technikum29-Computermuseum', 'The latest devices and news from the technikum29 computer museum'),
178                'rss-copyright' => array('Heribert Müller und das technikum29-Team', 'Heribert Müller and the technikum29 team'),
179               
180        );
181}
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