1<?php
2/**
3 * DokuWiki Bootstrap3 Template: Translation Plugin
4 *
5 * @link     http://dokuwiki.org/template:bootstrap3
6 * @author   Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 */
9
10global $ID;
11global $TPL;
12global $conf;
13
14$show_translation  = false;
15$translation_items = [];
16$translation_label = '';
17
18$translation = $TPL->getPlugin('translation');
19
20$conf['plugin']['translation']['dropdown'] = 0;
21
22if ($translation->istranslatable($ID)) {
23
24    $show_translation = true;
25
26    list($lc, $idpart) = $translation->getTransParts($ID);
27
28    $translation_label = $translation->getLang('translations');
29
30    foreach ($translation->translations as $t) {
31
32        // Old version of Translation plugin
33        if (method_exists($translation, 'getTransItem')) {
34            $translation_items[] = str_replace(array('<div class="li">', '</div>'), '', $translation->getTransItem($t, $idpart));
35        } else {
36
37            list($target, $language) = $translation->buildTransID($t, $idpart);
38
39            $target = cleanID($target);
40            $exists = page_exists($target, '', false);
41            $link   = wl($target);
42
43            $text  = '';
44            $title = hsc($translation->getLocalName($language));
45
46            if (isset($translation->opts['flag'])) {
47                $text .= '<i>' . inlineSVG(DOKU_PLUGIN . 'translation/flags/' . $language . '.svg', 1024 * 12) . '</i>';
48            }
49
50            if (isset($translation->opts['name'])) {
51
52                $text .= hsc($translation->getLocalName($language));
53
54                if (isset($translation->opts['langcode'])) {
55                    $text .= ' (' . hsc($language) . ')';
56                }
57
58            } elseif (isset($translation->opts['langcode'])) {
59                $text .= hsc($language);
60            }
61
62            $translation_items[] = '<li class="menuitem"><a href="' . $link . '" class="' . ($exists ? 'wikilink1' : 'wikilink2') . '" title="' . $title . '">' . $text . '</a></li>';
63
64        }
65    }
66
67}
68
69if ($show_translation):
70?>
71<!-- translation -->
72<ul class="nav navbar-nav" id="dw__translation">
73    <li class="dropdown">
74        <a href="<?php wl($ID)?>" class="dropdown-toggle" data-target="#" data-toggle="dropdown" title="<?php echo $translation_label ?>" role="button" aria-haspopup="true" aria-expanded="false">
75            <?php echo iconify('mdi:flag'); ?> <span class="hidden-lg hidden-md hidden-sm"><?php echo $translation_label ?></span><span class="caret"></span>
76        </a>
77        <ul class="dropdown-menu" role="menu">
78
79            <?php if ($translation->getConf('about') || $translation->getConf('title')): ?>
80            <li class="dropdown-header hidden-xs hidden-sm">
81                <?php
82
83                    echo iconify('mdi:flag');
84                    echo $translation->getLang('translations');
85
86                    if ($translation->getConf('about')) {
87                        echo ' ' . $translation->showAbout();
88                    }
89                ?>
90            <?php endif;?>
91            </li>
92
93            <?php
94                foreach ($translation_items as $item) {
95                    echo $item;
96                }
97            ?>
98
99        </ul>
100    </li>
101</ul>
102<!-- /translation -->
103<?php endif;?>
104