Dotclear

source: locales/po_update.sh @ 0:54703be25dd6

Revision 0:54703be25dd6, 3.9 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

2.3 branch (trunk) first checkin

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

Sites map