Dotclear

source: build-tools/po_update.sh @ 1977:0e8863856b51

Revision 1977:0e8863856b51, 4.0 KB checked in by Dsls, 12 years ago (diff)

Introducing buildtools fake plugin (not to be included in releases).

Resync l10n .po/.pot files

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

Sites map