1 | <?php |
---|
2 | |
---|
3 | if(realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) { |
---|
4 | header('Content-Type: application/json'); |
---|
5 | if(isset($_GET['pre'])) echo $_GET['pre']; |
---|
6 | echo t29Messages::create_json(); |
---|
7 | if(isset($_GET['post'])) echo ";\n".$_GET['post']; |
---|
8 | } |
---|
9 | |
---|
10 | class t29Messages { |
---|
11 | public $lang; |
---|
12 | public static $order = array('de' => 0, 'en' => 1); |
---|
13 | |
---|
14 | function __construct($lang) { |
---|
15 | $this->lang = $lang; |
---|
16 | } |
---|
17 | |
---|
18 | function _($str_id) { |
---|
19 | if(!isset(self::$msg[$str_id])) { |
---|
20 | return "<$str_id>"; // error; mediawiki style |
---|
21 | } else { |
---|
22 | if(is_array(self::$msg[$str_id])) { |
---|
23 | return self::$msg[$str_id][ self::$order[$this->lang] ]; |
---|
24 | } else |
---|
25 | return self::$msg[$str_id]; |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | /** |
---|
30 | * $msg = new t29Messages("foo"); |
---|
31 | * print $msg->_("foobar"); // ordinary long version |
---|
32 | * $_ = $msg->get_shorthand_printer(); |
---|
33 | * $_("foobar"); // same but shorter |
---|
34 | **/ |
---|
35 | function get_shorthand_printer() { |
---|
36 | $t = $this; |
---|
37 | return function($str)use($t) { print $t->_($str); }; |
---|
38 | } |
---|
39 | |
---|
40 | /// same but return instead of print |
---|
41 | function get_shorthand_returner() { |
---|
42 | $t = $this; |
---|
43 | return function($str)use($t) { return $t->_($str); }; |
---|
44 | } |
---|
45 | |
---|
46 | static function create_json($filter_regexp=false) { |
---|
47 | $msg = $filter_regexp ? array_intersect_key(self::$msg, |
---|
48 | array_flip(preg_grep($filter_regexp, array_keys(self::$msg))) |
---|
49 | ) : self::$msg; |
---|
50 | return json_encode(array( |
---|
51 | 'order' => self::$order, |
---|
52 | 'msg' => $msg |
---|
53 | )); |
---|
54 | } |
---|
55 | |
---|
56 | public static $msg = array( |
---|
57 | 'html-title' => 'technikum29', |
---|
58 | 'head-h1-title' => array('Zur technikum29 Startseite', 'Go to technikum29 homepage'), |
---|
59 | 'head-h1' => 'technikum29', |
---|
60 | |
---|
61 | 'sidebar-h2-tour' => array('Museumstour', 'Museum Tour'), |
---|
62 | 'sidebar-h2-mainnav' => array('Hauptnavigation', 'Main Navigation'), |
---|
63 | 'sidebar-h2-lang' => array('Sprachauswahl', 'Language'), |
---|
64 | |
---|
65 | 'topnav-interlang-title' => array('Read this page (%s) in English', 'Diese Seite (%s) auf Deutsch lesen'), |
---|
66 | 'topnav-search-label' => array('Suchen', 'Search'), |
---|
67 | |
---|
68 | 'js-menu-collapse-out' => array('Menü ausklappen', 'Expand menu'), |
---|
69 | 'js-menu-collapse-in' => array('Menü einklappen', 'Fold menu'), |
---|
70 | 'js-menu-scroll-show' => array('Menü einblenden', 'Show menu'), |
---|
71 | 'js-menu-scroll-hide' => array('Menü ausblenden', 'Hide menu'), |
---|
72 | |
---|
73 | 'footer-copyright-tag' => '© 2003-2012 technikum29.', |
---|
74 | 'footer-legal-link' => array('Impressum und Kontakt', 'Legal notices'), |
---|
75 | 'footer-legal-file' => array('/impressum.php', '/contact.php'), |
---|
76 | |
---|
77 | 'nav-rel-prev' => array('vorherige Seite', 'previous page'), |
---|
78 | 'nav-rel-next' => array('nächste Seite', 'next page'), |
---|
79 | 'nav-rel-start' => array('Starte Führrung', 'Start guided tour'), |
---|
80 | |
---|
81 | 'head-rel-first' => array('Deutscher Start', 'English start'), |
---|
82 | 'head-rel-prev' => array('Zur vorherigen Seite (%s)', 'Previous Page (%s)'), |
---|
83 | 'head-rel-next' => array('Zur folgenden Seite (%s)', 'Next Page (%s)'), |
---|
84 | 'head-rel-interlang' => array('Englische Version dieser Seite (%s)', 'Deutsche Version dieser Seite (%s)'), |
---|
85 | ); |
---|
86 | } |
---|