aboutsummaryrefslogtreecommitdiffstats
path: root/en/doc/doc.php
blob: 3c352b08f9729d13d6d275ceced76fe4030ca261 (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
<?php

$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');
$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['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 {
        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="dlt2 dlinfo"  style="font-size: 10pt;">' . PHP_EOL;
    $table .= "\t<tbody>" . 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/> <span style="font-size: 07pt;">('.
                                        _r('also as file:') . ' %s)</span>',
                                        '<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 <span style="font-size: 07pt;">(%s%s)</span>',
                $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 = '<span style="font-weight:bold">' . _r('Other languages:') . '</span>';
        }
        $table .= sprintf("\t\t<tr><td>%s</td></tr>" . PHP_EOL .
                        "\t\t<tr><td>&nbsp;</td></tr>" . PHP_EOL .
                        "\t\t<tr><td>%s</td></tr>" . PHP_EOL,
                        $your_language, $text_others);
    } 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('Please help <a href="../community/">us</a> translate it in your language.') . '<br/>';
        $table .= sprintf("\t\t<tr><td>%s</td></tr>" . PHP_EOL .
                        "\t\t<tr><td>%s</td></tr>" . PHP_EOL . '%s' .
                        "\t\t<tr><td>&nbsp;</td></tr>" . PHP_EOL,
                        '<span style="font-weight:bold">' . $documentation_name . '</span>', $text_your_language, $language_present_before);
    }
    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;
}