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