Dotclear

source: locales/po_update.sh @ 81:a5edb17cf25d

Revision 81:a5edb17cf25d, 3.9 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Update script to include new plugin userPref

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

Sites map