Dotclear

source: build-tools/po_update.sh @ 2271:c088c62dd5b2

Revision 2271:c088c62dd5b2, 4.0 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Bye bye daInstaller ;-)

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

Sites map