aboutsummaryrefslogtreecommitdiffstats
path: root/en/doc/doc.php
blob: e0868687ab9f38f38db5bb9c27d0ca15bbd1826a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php

$documentation['installer'     ][7] = array('ca','cs','de','el','en','eo','es','et','eu','fr','hr','hu','ja','nb','nl','pl','pt_br','ro','ru','sk','sl','sq','sv','tr','uk','zh_cn');
$documentation['control_center'][7] = array('ca','cs','da','de','el','en','es','et','eu','fr','id','it','ja','nb','nl','pl','pt_br','ro','ru','sl','sq','sv','tr','uk','zh_cn');
$documentation['draklive'      ][7] = array('cs','de','el','en','es','et','eu','fr','hr','ja','nl','pt_br','ro','sk','sl','sq','sv','uk','zh_cn');
$documentation['netinstall'    ][7] = array('ca','cs','de','el','en','es','et','eu','fr','hu','ja','nb','nl','pt_br','ru','sq','sl','sv','tr','uk','zh_cn');

$documentation['installer'     ][6] = array('ca','cs','de','el','en','eo','es','et','eu','fr','hr','hu','id','it','nb','nl','pl','pt','pt_br','ro','ru','sk','sl','sq','sv','tr','uk','zh_CN');
$documentation['control_center'][6] = array('ca','cs','da','de','el','en','es','et','eu','fr','id','it','nl','pl','pt','pt_br','ro','ru','sl','sq','sv','tr','uk','zh_CN');
$documentation['draklive'      ][6] = array('cs','de','el','en','es','et','eu','fr','hr','nb','nl','pt_br','ro','ru','sk','sl','sq','sv','tr','uk','zh_CN');
$documentation['netinstall'    ][6] = array('ca','cs','de','el','en','es','et','eu','fr','nb','nl','pt_br','sl','sv','tg','tr','uk','zh_CN');

$documentation['installer'     ][5] = array('ca','cs','de','el','en','eo','es','et','eu','fr','hr','id','it','nl','pl','pt','pt_br','ro','ru','sq','sv','tr','uk','zh_CN');
$documentation['control_center'][5] = array('ca','cs','de','el','en','es','et','eu','fr','id','it','nl','pl','pt','pt_br','ro','ru','sv','tr','uk');
$documentation['draklive'      ][5] = array('cs','de','el','en','es','et','eu','fr','hr','nl','ro','sk','sl','sv','uk','zh_CN');

$documentation['installer'     ][4] = array('ca','cs','de','el','en','eo','es','et','fr','id','nl','pl','pt_br','ro','ru','sv','tr','uk');
$documentation['control_center'][4] = array('en','et','fr','ru','tr','uk');

$documentation['installer'     ][3] = array('de','el','en','es','et','fr','nl','pt_br','ru','uk');
$documentation['control_center'][3] = array('en','et','fr');

$documentation['installer'     ][2] = array('de','el','en','eo','fr','nl','pt_br','uk');

$defs = parse_ini_file('../downloads/get/definitions_doc.ini', true);

function pdf_epub_present_in_locale($doc_name, $lang, $extension)
{
    global $defs;

    $eng_file_name = sprintf('%s_en_%s', $doc_name, $extension);
    if(array_key_exists($eng_file_name, $defs)) {
        $langs = explode('|', $defs[$eng_file_name]['langs']);
        if (in_array($lang, $langs)) {
            return TRUE;
        }
    }
    return FALSE;
}

function doc_present_in_locale($documentation_name, $version)
{
    global $locale;
    global $documentation;
    $link_locale = locale_hyphen_underscore($locale); // create pt_br.po from pt-br and alike
    if (in_array($link_locale, $documentation[$documentation_name][$version])) {
        return $link_locale;
    } else {
        return 'en';
    }
}

function doc_list($documentation_name, $type, $version)
{
    global $locale;
    global $langs;
    global $documentation;

    if ('control_center' == $type) {
        $dir   = 'mcc';
        $name  = 'MCC';
        $title = _r('Control Center');
    } else if ('installer' == $type) {
        $dir   = 'installer';
        $name  = 'DrakX';
        $title = _r('Installer');
    } else if ('draklive' == $type) {
        $dir   = 'draklive';
        $name  = 'DrakLive';
        $title = _r('Installation from LIVE medium');
    } else if ('netinstall' == $type) {
        $dir   = 'netinstall';
        $name  = 'NetInstall';
        $title = _r('Installation with tiny boot image');
    } else {
        return; // proper $type not defined ;)
    }

    $doc_link = sprintf('<a href="//doc.mageia.org/%s/%s/%s/content/index.html">%s</a>', $dir, $version, '%s', '%s');
    $pdf_link  = sprintf('<a rel="nofollow" href="../downloads/get/?q=Mageia%s-%s-%s-pdf&amp;doc=yes" title="Mageia %s PDF">PDF</a>', $version, $name, '%s', $title);
    $epub_link = sprintf('<a rel="nofollow" href="../downloads/get/?q=Mageia%s-%s-%s-epub&amp;doc=yes" title="Mageia %s EPUB">EPUB</a>', $version, $name, '%s', $title);

    $link_locale = locale_hyphen_underscore($locale); // create pt_br.po from pt-br and alike
    $your_language = '';
    $others = array();
    $text_others = '';
    $your_language_present = FALSE;
    $other_languages_present = FALSE;
    $note_printed = FALSE;
    $table = PHP_EOL . '<table class="table table-sm">' . PHP_EOL;

    foreach ($documentation[$type][$version] as $lng) {
        // hopefully temporary exception for pt-br as convention for lang-abbrev in /langs.inc.php is different as link in doc.mageia.org
        $lng_name = $langs[locale_underscore_to_hyphen($lng)];

        $pdf_present  = pdf_epub_present_in_locale(sprintf('Mageia%s_%s', $version, $name), $lng, 'pdf');
        $epub_present = pdf_epub_present_in_locale(sprintf('Mageia%s_%s', $version, $name), $lng, 'epub');
        $pdf_epub_links = array();
        if ($pdf_present) {
            $pdf_epub_links[] = sprintf($pdf_link, $lng);
        }
        if ($epub_present) {
            $pdf_epub_links[] = sprintf($epub_link, $lng);
        }
        $pdf_epub_links = implode(', ', $pdf_epub_links);
        $lang_doc_link = sprintf($doc_link, $lng, $lng_name);

        if ($link_locale == $lng) {
            $your_language_present = TRUE;
            if (!$pdf_present && !$epub_present) {
                $your_language = sprintf(_r('Online manual for %s available in %s') . '<br/>',
                                        '<span style="font-weight:bold">' . $documentation_name . '</span>', $lang_doc_link);
            } else {
                $your_language = sprintf(_r('Online manual for %s available in %s') . '<br/> <small class="text-mutted">('.
                                        _r('also as file:') . ' %s)</small>',
                                        '<span style="font-weight:bold">' . $documentation_name . '</span>',
                                        $lang_doc_link, $pdf_epub_links);
            }
        } else {
            $other_languages_present = TRUE;
            if (!$pdf_present && !$epub_present) {
                $others[] = $lang_doc_link;
            } else {
                if(!$note_printed) {
                    $note = _r('also as file:', ' ');
                    $note_printed = TRUE;
                } else {
                    $note = '';
                }
                $others[] = sprintf('%s <small class="text-muted">(%s%s)</small>',
                $lang_doc_link, $note, $pdf_epub_links, $lang_doc_link);
            }
        }
    }
    if ($your_language_present) {
        $text_your_language = '<span style="font-weight:bold">' . _r('Documentation in your language:') . '</span><br/>';
        if ($other_languages_present) {
            $text_others = '<a class="btn btn-sm btn-outline-primary" data-toggle="collapse" href="#table-'.$name.'-'.$version.'" role="button" aria-expanded="false" aria-controls="table-'.$name.'-'.$version.'">' . _r('Other languages:') . ' &#x2198; </a>';
        }
        $table .= sprintf("\t<caption class=\"caption-top\">%s</caption>" . PHP_EOL .
                        "\t<thead><tr><th class=\"border-0\">%s</th></tr></thead>" . PHP_EOL .
                        '<tbody class="collapse" id="table-%s-%s">' . PHP_EOL ,
                        $your_language, $text_others, $name, $version);
    } else {
        foreach($documentation[$type] as $single_version => $all_languages) {
            if($single_version < $version && in_array($link_locale, $all_languages)) {
                $language_present_before = "\t\t<tr><td>" .
                    sprintf(_r('Translation was present in %s before.<br/>Maybe you can check documentation for %s in Mageia %s.'),
                            $langs[locale_underscore_to_hyphen($locale)], $documentation_name, $single_version) . "</td></tr>" . PHP_EOL;
                break;
            } else {
                $language_present_before = '';
            }
        }
        $text_your_language = _r('Not <a href="../community/">yet</a> available in your language.') . ' ' . _r('Click below for alternative available languages.') . '<br/>';
        $table .= sprintf("\t<caption class=\"caption-top\">%s<br/>" . PHP_EOL .
                        "\t%s<a class=\"btn btn-sm btn-outline-primary\" data-toggle=\"collapse\" href=\"#table-$name-$version\" role=\"button\" aria-expanded=\"false\" aria-controls=\"table-$name-$version\"> &#x2198; </a></caption>" . PHP_EOL . '%s' .
                        "\t<tbody class=\"collapse\" id=table-%s-%s>" . PHP_EOL ,
                        '<span style="font-weight:bold">' . $documentation_name . '</span>', $text_your_language, $language_present_before, $name, $version);
    }
    foreach ($others as $other_languages) {
        $table .= sprintf("\t\t<tr><td>%s</td></tr>" . PHP_EOL, $other_languages);
    }
    $table .= "\t</tbody>" . PHP_EOL;
    $table .= "</table>" . PHP_EOL;

    echo $table;
}