Dotclear

source: build-tools/po_update.sh @ 3731:3770620079d4

Revision 3731:3770620079d4, 3.8 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

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

Sites map