Changeset 276 in t29-www for lib


Ignore:
Timestamp:
Jul 7, 2012, 7:45:22 PM (12 years ago)
Author:
sven
Message:

Weitere Fixes in den Geräteseiten:

  • Univac-Geräteseiten konvertiert
  • Interlang-System verbessert (bessere Ausgabe bei nicht existierenden Interlang-Links)
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/messages.php

    r273 r276  
    1717        /// when instanciated, stores the language to lookup for _()
    1818        public $lang;
    19 
     19       
    2020        /// The order of array elements in $msg. This array maps
    2121        /// $lang shortstring to array index position.
     
    3030         * There's actually no long method name version :D
    3131         * @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)
    3233         * @returns Found string in current locale ($lang)
    3334         **/
    34         function _($str_id) {
     35        function _($str_id, $lang=null) {
     36                $lang = ($lang && isset(self::$order[$lang])) ? $lang : $this->lang;
    3537                if(!isset(self::$msg[$str_id])) {
    3638                        return "<$str_id>"; // error; mediawiki style
    3739                } else {
    3840                        if(is_array(self::$msg[$str_id])) {
    39                                 return self::$msg[$str_id][ self::$order[$this->lang] ];
     41                                return self::$msg[$str_id][ self::$order[$lang] ];
    4042                        } else
    4143                                return self::$msg[$str_id];
     
    5355        function get_shorthand_printer() {
    5456                $t = $this;
    55                 return function($str)use($t) { print $t->_($str); };
     57                return function($str,$lang=null)use($t) { print $t->_($str,$lang); };
    5658        }
    5759
     
    5961        function get_shorthand_returner() {
    6062                $t = $this;
    61                 return function($str)use($t) { return $t->_($str); };
     63                return function($str,$lang=null)use($t) { return $t->_($str,$lang); };
    6264        }
    6365
     
    9496                'sidebar-h2-lang'        => array('Sprachauswahl', 'Language'),
    9597
    96                 'topnav-interlang-title' => array('Read this page (%s) in English', 'Diese Seite (%s) auf Deutsch lesen'),
     98                'topnav-interlang-title' => array('Die Seite "%s" auf Deutsch lesen', 'Read the page "%s" in English'),
     99                'topnav-interlang-active' => array('Sie betrachten gerade die Seite "%s" auf Deutsch', 'You currently read the page "%s" in English'),
     100                'topnav-interlang-nonexistent' => array('Diese Seite steht auf Deutsch nicht zur Verfügung', 'This page is not available in English'),
    97101                'topnav-search-label'    => array('Suchen', 'Search'),
    98102                'topnav-search-page'     => array('/suche.php', '/search.php'),
     
    115119                'head-rel-prev'          => array('Zur vorherigen Seite (%s)', 'Previous Page (%s)'),
    116120                '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)'),
     121                'head-rel-interlang'     => array('Deutsche Version dieser Seite (%s)', 'English Version of this page (%s)'),
    118122               
    119123                // used in /shared/js/modules/heading_links.js
  • lib/template.php

    r275 r276  
    121121        // print interlanguage links for all languages except the active one
    122122        foreach($this->interlang_links as $lang => $a) {
    123                 if($lang != $this->conf['lang']) {
     123                if($lang != $this->conf['lang'] && !is_null($a)) {
    124124                        printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">',
    125                                 $a['href'], $lang, sprintf($_('head-rel-interlang'), $a)
     125                                $a['href'], $lang, sprintf($_('head-rel-interlang', $lang), $a)
    126126                        );
    127127                }
     
    192192                                <?php
    193193                                        foreach($this->interlang_links as $lang => $a) {
     194                                                $is_current_lang = $lang == $this->conf['lang'];
     195                                                if(is_null($a)) {
     196                                                        // when interlanguage link not present (null) = no translation exists
     197                                                        $a = t29Menu::dom_new_link('#', 'not present');
     198                                                        $title = sprintf($_('topnav-interlang-nonexistent', $lang));
     199                                                        $class = 'nonexistent';
     200                                                } elseif($is_current_lang) {
     201                                                        $title = sprintf($_('topnav-interlang-active'), $a);
     202                                                        $class = 'active';
     203                                                } else {
     204                                                        // ordinary interlang link
     205                                                        $title = sprintf($_('topnav-interlang-title', $lang), $a);
     206                                                        $class = '';
     207                                                }
    194208                                                printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n",
    195                                                         ($lang == $this->conf['lang'] ? ' class="active"' : ''),
    196                                                         $a['href'], sprintf($_('topnav-interlang-title'), $a),
     209                                                        (empty($class) ? '' : " class='$class'"),
     210                                                        $a['href'], htmlspecialchars($title),
    197211                                                        $this->conf['languages'][$lang][0] // verbose language name
    198212                                                );
Note: See TracChangeset for help on using the changeset viewer.
© 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