Dotclear

source: build-tools/po_update.sh @ 2739:856bff6ae053

Revision 2739:856bff6ae053, 4.0 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Fix issue when testing editor
Translation for dcLegacyEditor and dcCKEditor are now managed

  • Property exe set to *
Line 
1#!/bin/sh
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13# Usage (from l10n-plugins root)
14# po_update.sh <dotclear-root> [<lang>]
15
16export LANG=C
17
18XGETTEXT=xgettext
19MSGMERGE=msgmerge
20
21PLUGINS="
22aboutConfig
23akismet
24antispam
25attachments
26blogroll
27blowupConfig
28dclegacy
29fairTrackbacks
30importExport
31maintenance
32pages
33pings
34simpleMenu
35tags
36themeEditor
37userPref
38widgets
39dcLegacyEditor
40dcCKEditor
41_fake_plugin
42"
43
44PO_LANG=$1
45PO_MODULE=$2
46
47if [ ! -d ./inc/core ]; then
48     echo "You are not on Dotclear root directory"
49     exit 1
50fi
51
52if [ ! -d locales/_pot ]; then
53     echo "Template not found."
54     exit 1
55fi
56
57extract_strings()
58{
59     $XGETTEXT \
60     -f- \
61     --sort-by-file \
62     -L PHP -k"__:1,2" -k"__:1" \
63     --no-wrap \
64     --foreign-user \
65     --from-code=UTF-8 \
66     "$@"
67}
68
69extract_html_strings()
70{
71     tee -
72
73     $XGETTEXT \
74     - \
75     --sort-by-file \
76     -L PHP -k__ \
77     --no-wrap \
78     --foreign-user \
79     --from-code=UTF-8 \
80     "$@"
81}
82update_po()
83{
84     po_file=$1
85     pot_file=$2
86     po_dir=`dirname $1`
87     po_tmp=$po_dir/tmp.po~
88
89     if [ ! -d $po_dir ]; then
90          mkdir $po_dir
91     fi
92
93     if [ ! -f $po_file ]; then
94          cp $pot_file $po_file
95          perl -pi -e "s|; charset=CHARSET|; charset=UTF-8|sgi;" $po_file $po_file
96     fi
97
98     $MSGMERGE --no-location --no-wrap -o $po_tmp $po_file $pot_file
99     mv $po_tmp $po_file
100}
101
102if [ -z "$PO_MODULE" ]; then
103     #
104     # Create po template files
105     #
106     echo "Building main PO template..."
107     find ./admin ./inc -name '*.php' -not -regex '.*/inc/public/.*' -print | \
108          extract_strings \
109          --package-name="Dotclear 2" \
110          -o locales/_pot/main.pot \
111          -x locales/_pot/date.pot
112
113     echo "DONE"
114
115     # plugins.pot
116     echo "Building plugins PO template..."
117     for p in $PLUGINS; do
118          if [ -d plugins/$p ]; then
119               find ./plugins/$p -name '*.php' -print
120          fi
121     done | \
122          extract_strings \
123          --package-name="Dotclear 2" \
124          -o locales/_pot/plugins.pot \
125          -x locales/_pot/date.pot \
126          -x locales/_pot/main.pot
127
128     echo "DONE"
129
130     #
131     # Update locales/<lang> if needed
132     #
133     if [ -z "$PO_LANG" ]; then
134          exit 0;
135     fi
136
137     # Init locale if not present
138     if [ ! -d locales/$PO_LANG ]; then
139          mkdir -p locales/$PO_LANG/help
140
141          # Base help files
142          for i in locales/en/help/*.html; do
143               cp $i locales/$PO_LANG/help/core_`basename $i`
144          done
145          for i in $PLUGINS; do
146               if [ -f plugins/$i/help.html ]; then
147                    cp plugins/$i/help.html locales/$PO_LANG/help/$i.html
148               fi
149          done
150     fi
151
152     # update main.po
153     echo "Updating <$PO_LANG> po files..."
154     update_po ./locales/$PO_LANG/main.po ./locales/_pot/main.pot
155     update_po ./locales/$PO_LANG/plugins.po ./locales/_pot/plugins.pot
156     update_po ./locales/$PO_LANG/public.po ./locales/_pot/public.pot
157     update_po ./locales/$PO_LANG/date.po ./locales/_pot/date.pot
158else
159     #
160     # Plugin language update
161     #
162
163     if [ ! -d $PO_MODULE ]; then
164          echo "Module $PO_MODULE does not exist"
165          exit 1
166     fi
167     echo "Module $PO_MODULE language update"
168
169
170     #
171     # Building po template file
172     #
173     if [ ! -d $PO_MODULE/locales/_pot ]; then
174          mkdir -p $PO_MODULE/locales/_pot
175     fi
176     echo "Building main PO template..."
177     echo '<?php' >$PO_MODULE/__html_tpl_dummy.php
178     find $PO_MODULE -name '*.html' -exec grep -o '{{tpl:lang [^}]*}}' {} \; | sed 's/{{tpl:lang \(.*\)}}$/__\("\1")/' | sort -u \
179          >> $PO_MODULE/__html_tpl_dummy.php
180     sed -i "" 's/\$/\\\$/g' $PO_MODULE/__html_tpl_dummy.php
181
182     find $PO_MODULE -name '*.php' -print | \
183          extract_strings \
184          --package-name="Dotclear 2 `basename $PO_MODULE` module" \
185          -o $PO_MODULE/locales/_pot/main.pot \
186          -x locales/_pot/date.pot -x locales/_pot/main.pot -x locales/_pot/public.pot -x locales/_pot/plugins.pot
187
188     rm -f $PO_MODULE/__html_tpl_dummy.php
189
190     echo "DONE"
191
192     #
193     # Update locale/<lang>
194     #
195     if [ ! -d $PO_MODULE/locales/$PO_LANG ]; then
196          mkdir -p $PO_MODULE/locales/$PO_LANG
197     fi
198     echo "Updating module <$PO_MODULE> main <$PO_LANG> po file... "
199     update_po $PO_MODULE/locales/$PO_LANG/main.po $PO_MODULE/locales/_pot/main.pot
200fi
Note: See TracBrowser for help on using the repository browser.

Sites map