]> git.lyx.org Git - lyx.git/blob - development/tools/update-po.sh
Customization: correct some color names.
[lyx.git] / development / tools / update-po.sh
1 #!/bin/sh
2 # A script to check whether there have been any string changes.
3 # If it finds some, it commits the new po files and then updates
4 # the stats.
5
6 # The script expects an environment variable FARM that will provide 
7 # it with the location of the LyX www tree.
8
9 DEBUG="";
10 COMMIT="";
11
12 while getopts ":cdh" options $ARGS; do
13   case $options in
14     c)  COMMIT="TRUE";;
15     d)  DEBUG="echo";;
16     h)  echo "update-po.sh [-c] [-d]"; 
17         echo "-c: Commit any changes we find.";
18         echo "-d: Debugging mode.";
19         echo "You must also point the FARM variable to LyX's www tree."; 
20         exit 0;;
21   esac
22 done
23
24 if [ -z "$FARM" ]; then
25   echo "You must set the FARM variable to run this script, e.g.:";
26   echo "# FARM=/cvs/lyx-www/ bash check-po.sh";
27   exit 1;
28 fi
29
30 FARM=${FARM%/};
31 FARM="$FARM/farm/cookbook/LyX";
32 # Sanity check
33 if [ ! -f "$FARM/i18n.php" ]; then 
34   echo "$FARM does not look like LyX's www tree!";
35   exit 1;
36 fi
37
38 # Get us to the root of the tree we are in.
39 MYDIR=${0%update-po.sh};
40 if [ -n "$MYDIR" ]; then
41   if ! cd $MYDIR; then
42     echo "Couldn't cd to $MYDIR!";
43     exit 1;
44   fi
45 fi
46 cd ../../;
47 LYXROOT=$(pwd);
48
49 # We need to make sure that we have a tree without any unstaged 
50 # commits. Otherwise commit will fail.
51 if git status --porcelain -uno | grep -q .; then
52   echo "Your git tree is not clean. Please correct the situation and re-run.";
53   echo;
54   git status --porcelain -uno;
55   exit 10;
56 fi
57
58 # Are we in trunk or branch?
59 TRUNK="TRUE";
60 if ls status.* 2>/dev/null | grep -q status; then 
61   TRUNK="";
62 fi
63
64 # Sanity check
65 if ! cd po/; then 
66   echo "Cannot cd to po/ directory!";
67   pwd
68   exit 1;
69 fi
70
71 echo Remerging...
72 make update-po >/dev/null 2>&1;
73 echo
74
75 if [ -n "$TRUNK" ]; then
76   I18NFILE=i18n_trunk.inc;
77 else
78   I18NFILE=i18n.inc;
79 fi
80
81 # make sure things are clean
82 rm -f i18n.inc;
83 svn revert $FARM/$I18NFILE;
84
85 echo Running make i18n.inc...
86 make i18n.inc  >/dev/null 2>&1;
87 if [ -n "$TRUNK" ]; then
88   mv -f i18n.inc i18n_trunk.inc
89 fi
90
91 if diff -w -q $I18NFILE $FARM/$I18NFILE >/dev/null 2>&1; then
92   echo No string differences found.
93   git checkout *.po;
94   exit 0;
95 fi
96
97 # So there are differences.
98 if [ -z "$COMMIT" ]; then
99   echo "Differences found!";
100   diff -wu $FARM/$I18NFILE $I18NFILE | less;
101   git checkout *.po *.gmo;
102   exit 0;
103 fi
104
105 $DEBUG git commit *.po *.gmo -m "Remerge strings.";
106 COMMITS=$(git push -n 2>&1 | tail -n 1 | grep -v "Everything" | sed -e 's/^ *//' -e 's/ .*//');
107
108 if [ -z "$COMMITS" ]; then
109   echo "We seem to be missing the commit of the po files!";
110   exit 1;
111 fi
112
113 git log $COMMITS;
114
115 #Do we want to go ahead?
116 echo
117 echo "Do you want to push these commits?"
118 select answer in Yes No; do
119   if [ "$answer" != "Yes" ]; then
120     echo "You will need to push that commit manually, then.";
121     break;
122   else 
123     git push;
124     break;
125   fi
126 done
127
128 echo
129
130 if ! cd $FARM; then
131   echo "Unable to cd to $FARM!";
132   exit 1;
133 fi
134
135 echo Updating the www-user tree...
136 # note that we're assuming this one is svn.
137 svn up;
138
139 echo Moving $I18NFILE...;
140 mv $LYXROOT/po/$I18NFILE .;
141
142 echo Committing...;
143 $DEBUG svn commit -m "* $I18NFILE: update stats" $I18NFILE;
144