[0] | 1 | #!/bin/sh |
---|
[3731] | 2 | # @package Dotclear |
---|
[0] | 3 | # |
---|
[3731] | 4 | # @copyright Olivier Meunier & Association Dotclear |
---|
| 5 | # @copyright GPL-2.0-only |
---|
[0] | 6 | # |
---|
| 7 | # Usage (from l10n-plugins root) |
---|
| 8 | # po_update.sh <dotclear-root> [<lang>] |
---|
| 9 | |
---|
| 10 | export LANG=C |
---|
| 11 | |
---|
| 12 | XGETTEXT=xgettext |
---|
| 13 | MSGMERGE=msgmerge |
---|
| 14 | |
---|
| 15 | PLUGINS=" |
---|
| 16 | aboutConfig |
---|
| 17 | akismet |
---|
| 18 | antispam |
---|
[750] | 19 | attachments |
---|
[0] | 20 | blogroll |
---|
| 21 | blowupConfig |
---|
[3009] | 22 | breadcrumb |
---|
[2283] | 23 | dclegacy |
---|
[0] | 24 | fairTrackbacks |
---|
| 25 | importExport |
---|
| 26 | maintenance |
---|
| 27 | pages |
---|
| 28 | pings |
---|
[750] | 29 | simpleMenu |
---|
[0] | 30 | tags |
---|
| 31 | themeEditor |
---|
[750] | 32 | userPref |
---|
[0] | 33 | widgets |
---|
[2739] | 34 | dcLegacyEditor |
---|
| 35 | dcCKEditor |
---|
[1977] | 36 | _fake_plugin |
---|
[0] | 37 | " |
---|
| 38 | |
---|
| 39 | PO_LANG=$1 |
---|
| 40 | PO_MODULE=$2 |
---|
| 41 | |
---|
| 42 | if [ ! -d ./inc/core ]; then |
---|
[3784] | 43 | echo "You are not on Dotclear root directory" |
---|
| 44 | exit 1 |
---|
[0] | 45 | fi |
---|
| 46 | |
---|
| 47 | if [ ! -d locales/_pot ]; then |
---|
[3784] | 48 | echo "Template not found." |
---|
| 49 | exit 1 |
---|
[0] | 50 | fi |
---|
| 51 | |
---|
| 52 | extract_strings() |
---|
| 53 | { |
---|
[3784] | 54 | $XGETTEXT \ |
---|
| 55 | -f- \ |
---|
| 56 | --sort-by-file \ |
---|
| 57 | -L PHP -k"__:1,2" -k"__:1" \ |
---|
| 58 | --no-wrap \ |
---|
| 59 | --foreign-user \ |
---|
| 60 | --from-code=UTF-8 \ |
---|
| 61 | "$@" |
---|
[0] | 62 | } |
---|
| 63 | |
---|
| 64 | extract_html_strings() |
---|
| 65 | { |
---|
[3784] | 66 | tee - |
---|
[2566] | 67 | |
---|
[3784] | 68 | $XGETTEXT \ |
---|
| 69 | - \ |
---|
| 70 | --sort-by-file \ |
---|
| 71 | -L PHP -k__ \ |
---|
| 72 | --no-wrap \ |
---|
| 73 | --foreign-user \ |
---|
| 74 | --from-code=UTF-8 \ |
---|
| 75 | "$@" |
---|
[0] | 76 | } |
---|
| 77 | update_po() |
---|
| 78 | { |
---|
[3784] | 79 | po_file=$1 |
---|
| 80 | pot_file=$2 |
---|
| 81 | po_dir=`dirname $1` |
---|
| 82 | po_tmp=$po_dir/tmp.po~ |
---|
[2566] | 83 | |
---|
[3784] | 84 | if [ ! -d $po_dir ]; then |
---|
| 85 | mkdir $po_dir |
---|
| 86 | fi |
---|
[2566] | 87 | |
---|
[3784] | 88 | if [ ! -f $po_file ]; then |
---|
| 89 | cp $pot_file $po_file |
---|
| 90 | perl -pi -e "s|; charset=CHARSET|; charset=UTF-8|sgi;" $po_file $po_file |
---|
| 91 | fi |
---|
[2566] | 92 | |
---|
[3784] | 93 | $MSGMERGE --no-location --no-wrap -o $po_tmp $po_file $pot_file |
---|
| 94 | mv $po_tmp $po_file |
---|
[0] | 95 | } |
---|
| 96 | |
---|
| 97 | if [ -z "$PO_MODULE" ]; then |
---|
[3784] | 98 | # |
---|
| 99 | # Create po template files |
---|
| 100 | # |
---|
| 101 | echo "Building main PO template..." |
---|
| 102 | find ./admin ./inc -name '*.php' -not -regex '.*/inc/public/.*' -not -regex '.*/inc/libs/.*' -print | \ |
---|
| 103 | extract_strings \ |
---|
| 104 | --package-name="Dotclear 2" \ |
---|
| 105 | -o locales/_pot/main.pot \ |
---|
| 106 | -x locales/_pot/date.pot |
---|
[2566] | 107 | |
---|
[3784] | 108 | echo "DONE" |
---|
[2566] | 109 | |
---|
[3784] | 110 | # plugins.pot |
---|
| 111 | echo "Building plugins PO template..." |
---|
| 112 | for p in $PLUGINS; do |
---|
| 113 | if [ -d plugins/$p ]; then |
---|
| 114 | find ./plugins/$p -name '*.php' -print |
---|
| 115 | fi |
---|
| 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 |
---|
[2566] | 122 | |
---|
[3784] | 123 | echo "DONE" |
---|
[2566] | 124 | |
---|
[3784] | 125 | # |
---|
| 126 | # Update locales/<lang> if needed |
---|
| 127 | # |
---|
| 128 | if [ -z "$PO_LANG" ]; then |
---|
| 129 | exit 0; |
---|
| 130 | fi |
---|
[2566] | 131 | |
---|
[3784] | 132 | # Init locale if not present |
---|
| 133 | if [ ! -d locales/$PO_LANG ]; then |
---|
| 134 | mkdir -p locales/$PO_LANG/help |
---|
[2566] | 135 | |
---|
[3784] | 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 |
---|
[2566] | 146 | |
---|
[3784] | 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 |
---|
[0] | 153 | else |
---|
[3784] | 154 | # |
---|
| 155 | # Plugin language update |
---|
| 156 | # |
---|
[2566] | 157 | |
---|
[3784] | 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" |
---|
[2566] | 163 | |
---|
| 164 | |
---|
[3784] | 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 |
---|
| 175 | sed -i "" 's/\$/\\\$/g' $PO_MODULE/__html_tpl_dummy.php |
---|
[2566] | 176 | |
---|
[3784] | 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 |
---|
[2566] | 182 | |
---|
[3784] | 183 | rm -f $PO_MODULE/__html_tpl_dummy.php |
---|
[2566] | 184 | |
---|
[3784] | 185 | echo "DONE" |
---|
[2566] | 186 | |
---|
[3784] | 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 |
---|
[0] | 195 | fi |
---|