Dotclear

source: locales/po_update.sh @ 750:c40ad56281f2

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

Locales building is no more broken

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

Sites map