[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 |
---|
[1046] | 28 | daInstaller |
---|
[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 |
---|
| 39 | " |
---|
| 40 | |
---|
| 41 | PO_LANG=$1 |
---|
| 42 | PO_MODULE=$2 |
---|
| 43 | |
---|
| 44 | if [ ! -d ./inc/core ]; then |
---|
| 45 | echo "You are not on Dotclear root directory" |
---|
| 46 | exit 1 |
---|
| 47 | fi |
---|
| 48 | |
---|
| 49 | if [ ! -d locales/_pot ]; then |
---|
| 50 | echo "Template not found." |
---|
| 51 | exit 1 |
---|
| 52 | fi |
---|
| 53 | |
---|
| 54 | extract_strings() |
---|
| 55 | { |
---|
| 56 | $XGETTEXT \ |
---|
| 57 | -f- \ |
---|
| 58 | --sort-by-file \ |
---|
[1944] | 59 | -L PHP -k"__:1,2" -k"__:1" \ |
---|
[0] | 60 | --no-wrap \ |
---|
| 61 | --foreign-user \ |
---|
[750] | 62 | --from-code=UTF-8 \ |
---|
[0] | 63 | "$@" |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | extract_html_strings() |
---|
| 67 | { |
---|
| 68 | tee - |
---|
| 69 | |
---|
| 70 | $XGETTEXT \ |
---|
| 71 | - \ |
---|
| 72 | --sort-by-file \ |
---|
| 73 | -L PHP -k__ \ |
---|
| 74 | --no-wrap \ |
---|
| 75 | --foreign-user \ |
---|
[750] | 76 | --from-code=UTF-8 \ |
---|
[0] | 77 | "$@" |
---|
| 78 | } |
---|
| 79 | update_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 | |
---|
| 99 | if [ -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 | find ./plugins/$p -name '*.php' -print |
---|
| 116 | done | \ |
---|
| 117 | extract_strings \ |
---|
| 118 | --package-name="Dotclear 2" \ |
---|
| 119 | -o locales/_pot/plugins.pot \ |
---|
| 120 | -x locales/_pot/date.pot \ |
---|
| 121 | -x locales/_pot/main.pot |
---|
| 122 | |
---|
| 123 | echo "DONE" |
---|
| 124 | |
---|
| 125 | # |
---|
| 126 | # Update locales/<lang> if needed |
---|
| 127 | # |
---|
| 128 | if [ -z "$PO_LANG" ]; then |
---|
| 129 | exit 0; |
---|
| 130 | fi |
---|
| 131 | |
---|
| 132 | # Init locale if not present |
---|
| 133 | if [ ! -d locales/$PO_LANG ]; then |
---|
| 134 | mkdir -p locales/$PO_LANG/help |
---|
| 135 | |
---|
| 136 | # Base help files |
---|
| 137 | for i in locales/en/help/*.html; do |
---|
| 138 | cp $i locales/$PO_LANG/help/core_`basename $i` |
---|
| 139 | done |
---|
| 140 | for i in $PLUGINS; do |
---|
| 141 | if [ -f plugins/$i/help.html ]; then |
---|
| 142 | cp plugins/$i/help.html locales/$PO_LANG/help/$i.html |
---|
| 143 | fi |
---|
| 144 | done |
---|
| 145 | fi |
---|
| 146 | |
---|
| 147 | # update main.po |
---|
| 148 | echo "Updating <$PO_LANG> po files..." |
---|
| 149 | update_po ./locales/$PO_LANG/main.po ./locales/_pot/main.pot |
---|
| 150 | update_po ./locales/$PO_LANG/plugins.po ./locales/_pot/plugins.pot |
---|
| 151 | update_po ./locales/$PO_LANG/public.po ./locales/_pot/public.pot |
---|
| 152 | update_po ./locales/$PO_LANG/date.po ./locales/_pot/date.pot |
---|
| 153 | else |
---|
| 154 | # |
---|
| 155 | # Plugin language update |
---|
| 156 | # |
---|
| 157 | |
---|
| 158 | if [ ! -d $PO_MODULE ]; then |
---|
| 159 | echo "Module $PO_MODULE does not exist" |
---|
| 160 | exit 1 |
---|
| 161 | fi |
---|
| 162 | echo "Module $PO_MODULE language update" |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | # |
---|
| 166 | # Building po template file |
---|
| 167 | # |
---|
| 168 | if [ ! -d $PO_MODULE/locales/_pot ]; then |
---|
| 169 | mkdir -p $PO_MODULE/locales/_pot |
---|
| 170 | fi |
---|
| 171 | echo "Building main PO template..." |
---|
| 172 | echo '<?php' >$PO_MODULE/__html_tpl_dummy.php |
---|
| 173 | find $PO_MODULE -name '*.html' -exec grep -o '{{tpl:lang [^}]*}}' {} \; | sed 's/{{tpl:lang \(.*\)}}$/__\("\1")/' | sort -u \ |
---|
| 174 | >> $PO_MODULE/__html_tpl_dummy.php |
---|
[959] | 175 | sed -i "" 's/\$/\\\$/g' $PO_MODULE/__html_tpl_dummy.php |
---|
[0] | 176 | |
---|
| 177 | find $PO_MODULE -name '*.php' -print | \ |
---|
| 178 | extract_strings \ |
---|
| 179 | --package-name="Dotclear 2 `basename $PO_MODULE` module" \ |
---|
| 180 | -o $PO_MODULE/locales/_pot/main.pot \ |
---|
| 181 | -x locales/_pot/date.pot -x locales/_pot/main.pot -x locales/_pot/public.pot -x locales/_pot/plugins.pot |
---|
| 182 | |
---|
| 183 | rm -f $PO_MODULE/__html_tpl_dummy.php |
---|
| 184 | |
---|
| 185 | echo "DONE" |
---|
| 186 | |
---|
| 187 | # |
---|
| 188 | # Update locale/<lang> |
---|
| 189 | # |
---|
| 190 | if [ ! -d $PO_MODULE/locales/$PO_LANG ]; then |
---|
| 191 | mkdir -p $PO_MODULE/locales/$PO_LANG |
---|
| 192 | fi |
---|
| 193 | echo "Updating module <$PO_MODULE> main <$PO_LANG> po file... " |
---|
| 194 | update_po $PO_MODULE/locales/$PO_LANG/main.po $PO_MODULE/locales/_pot/main.pot |
---|
| 195 | fi |
---|