summaryrefslogtreecommitdiffstats
path: root/help3xsl/xhp2html.sh
blob: 7ba59588fa142457922d30a2c740f8e7dfa60e3c (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#/bin/bash

# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This script builds translated XHP file with helpex excutable
# and thes transform it to html pages
# 1) generates redirection from LibreOffice Help URL to right html page
#    in index.html with bookmark2file.js
# 2) generates bookmark_<APP>.js for index search
# 3) generates HTML pages with online_transform.xs
# 4) copy service files (css, js, media) to right place.
#
# Note: change rootHelpex variable to your local git build
#
# convert2HTML $outDirLang $outDirHTML $lang $productversion $online $fileTree &

function convert2HTML() {
#outDirLang =1
#outDirHTML =2
#lang =3
#productversion =4
#online=5
#filetree=6

###########################################
#
# Process translated XHP files
#
###########################################

xsltparm='--stringparam fileTree '$6' --stringparam local '$5' --stringparam Language '$3' --stringparam productversion '$4' --stringparam root '$1'/'

echo 'Conversion to HTML started for '$3
for filep in `find $1/text -name "*.xhp"`
do
DIR=${filep##*text/}
name=${DIR:0:-3}
outFile=$2'/text/'$name'html'
xsltproc $xsltparm -o $outFile online_transform.xsl $filep
done

###########################################
#
# Process tree files
#
###########################################

treePOFile=`mktemp`
echo $root/translations/source/$3/helpcontent2/source/auxiliary.po > $treePOFile

ALL_TREE='sbasic.tree  scalc.tree  schart.tree  shared.tree  simpress.tree  smath.tree  swriter.tree'

xhpFiles=$here/l10n/$productversion/$3/text

treeFileHTML=$outDirHTML/contents.js
rm -f $treeFileHTML
touch $treeFileHTML
echo 'document.getElementById("Contents").innerHTML='$'\047''\'>$treeFileHTML

xsltparm='--stringparam lang '$3' --stringparam productversion '$4
for tree in $ALL_TREE
do
treeSourceFile=$root'/helpcontent2/source/auxiliary/'$tree
treeTemp1=`mktemp`
treeTemp2=`mktemp`

"${exedir}/treex" -l $3 -i $treeSourceFile -m $treePOFile -o $treeTemp1 -r $xhpFiles

xsltproc $xsltparm -o $treeTemp2 get_tree.xsl $treeTemp1

awk 'NF' $treeTemp2>>$treeFileHTML

rm -f $treeTemp1 $treeTemp2
done
echo $'\047'';'>>$treeFileHTML

rm -f $treePOFile

echo 'Conversion to HTML finished for '$3
}

###########################################
#
# Start Main Process
#
###########################################

# Change root of git core
productversion='6.0'
local='no'
fileTree='/home/tdf/git/core/helpcontent2/help3xsl/html/'

rootHelpex=/home/tdf/git/core

ALL_LANGS='en-US am ar ast bg bn bn-IN bo bs ca ca-valencia cs da de dz el en-GB en-ZA eo es et eu fi fr gl gu he hi hr hu id is it ja ka km ko lo lt lv mk nb ne nl nn om pl pt-BR pt ro ru sid si sk sl sq sv ta tg tr ug uk vi zh-CN zh-TW'

here=`pwd`
root=$(realpath "$here/../..")

rm -rf $here/l10n
rm -rf $here/html

helpfiles=$root/helpcontent2/source/text

mkdir -p $here'/html/'$productversion

echo 'copy global service files'
cp index.html $here'/html/'
cp LOHelp.html $here'/html/'
cp index2.html $here'/html/'$productversion'/index.html'
cp help.js $here'/html/'$productversion'/'
cp jquery-3.1.1.min.js $here'/html/'$productversion'/'
cp normalize.css $here'/html/'$productversion'/'
cp default.css $here'/html/'$productversion'/'

cp -rap ../source/media $here'/html/'$productversion'/'
mkdir -p $here'/html/'$productversion'/media/icon-themes'
cp -rap ../../icon-themes/galaxy/* $here'/html/'$productversion'/media/icon-themes/'
ln -s $productversion html/latest

# Set helpex utilty and environment

while test ! -d "${rootHelpex}/instdir/program" ; do
if test "${dir}" = "/"; then
echo "error: cannot find \"program\" dir from \"$(pwd)\""
exit 1
fi
rootHelpex=$(readlink -f "${rootHelpex}/..")
done

exedir="${rootHelpex}"/workdir/LinkTarget/Executable
echo $exedir

export URE_BOOTSTRAP=file://"${rootHelpex}"/instdir/program/fundamentalrc123
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}"${rootHelpex}"/instdir/program

echo "setting URE_BOOTSTRAP to: ${URE_BOOTSTRAP}"
echo "setting search path to: ${LD_LIBRARY_PATH}"
echo "execing: ${exedir}/helpex"

###########################################
#
# Create the bookmark2file map
#
###########################################
stub1='var map={'
stub2='};'
ffile='html/'$productversion'/bookmark2file.js'
ffile2=/tmp/tmpbkm.txt
rm -f $ffile2 $ffile
find $helpfiles -type f -name "*.xhp" -exec xsltproc get_url.xsl {} + > $ffile2
echo $stub1 >> $ffile
awk 'NF' $ffile2 >> $ffile
echo $stub2 >> $ffile

###########################################
#
# Process languages
#
###########################################

for lang in $ALL_LANGS
do

echo 'Processing Language '$lang

outDirLang=$here'/l10n/'$productversion'/'$lang
mkdir -p $outDirLang

outDirHTML=$here'/html/'$productversion'/'$lang
mkdir -p $outDirHTML

# Special case of en-US, tehre is no translation to do

if [ "$lang" == en-US ];
then

cp -rap $helpfiles $outDirLang

else
# Create first all translations of xhp
translations=$root/translations/source/$lang/helpcontent2/source/text/

pofiles=`mktemp`
xhpfiles=`mktemp`

# gather all po files of dir
find $translations -type f >$pofiles

# For each po file
for ff in `cat $pofiles`
do
    echo 'Processing po file: '$ff
    potemp=`mktemp`
    echo $ff>$potemp
    name=${ff:0:-3}
    stub=${name##*text/}
    hlpFileDir=$helpfiles'/'$stub
    outDir=$outDirLang'/text/'$stub
    mkdir -p $outDir
    ls $hlpFileDir/*.xhp >$xhpfiles
    "${exedir}/helpex" -l $lang -mi $xhpfiles -m $potemp -o $outDir
    rm -f $potemp
done
fi

#extracting bookmarks
echo 'Extracting bookmarks'
./get_bookmark.sh $lang $productversion &

# converting to HTML
convert2HTML $outDirLang $outDirHTML $lang $productversion $local $fileTree &

rm -f $pofiles $xhpfiles
done
exit