]> git.lyx.org Git - lyx.git/blob - development/tools/update-po.sh
Allow to assign several extension to a given file format (#4798).
[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 "check-po.sh [-d]"; 
17         echo "You must also point the FARM variable to LyX's www tree."; 
18         exit 0;;
19   esac
20 done
21
22 if [ -z "$FARM" ]; then
23   echo "You must set the FARM variable to run this script, e.g.:";
24   echo "# FARM=/cvs/lyx-www/ bash check-po.sh";
25   exit 1;
26 fi
27
28 FARM=${FARM%/};
29 FARM="$FARM/farm/cookbook/LyX";
30 # Sanity check
31 if [ ! -f "$FARM/i18n.php" ]; then 
32   echo "$FARM does not look like LyX's www tree!";
33   exit 1;
34 fi
35
36 # Get us to the root of the tree we are in.
37 MYDIR=${0%update-po.sh};
38 if [ -n "$MYDIR" ]; then
39   if ! cd $MYDIR; then
40     echo "Couldn't cd to $MYDIR!";
41     exit 1;
42   fi
43 fi
44 cd ../../;
45 LYXROOT=$(pwd);
46
47 # Are we in trunk or branch?
48 TRUNK="TRUE";
49 if ls status.* 2>/dev/null | grep -q status; then 
50   TRUNK="";
51 fi
52
53 # Git or SVN?
54 VCS="";
55 if svn log >/dev/null 2>&1; then
56   VCS="svn";
57 elif git diff >/dev/null 2>&1; then
58   VCS="git";
59   # We need to make sure that we have a tree without any unpushed 
60   # commits. Otherwise git svn dcommit would commit more than we
61   # want.
62   if git status | grep -Pq 'Your branch is (?:ahead|behind)'; then
63     echo "Your git tree is not clean. Please correct the situation and re-run.";
64     echo;
65     git status;
66     exit 10;
67   fi
68 fi
69
70 if [ -z "$VCS" ]; then 
71   echo "Unable to determine version control system!";
72   exit 1;
73 fi
74
75 # Sanity check
76 if ! cd po/; then 
77   echo "Cannot cd to po/ directory!";
78   pwd
79   exit 1;
80 fi
81
82 echo Remerging...
83 make update-po >/dev/null 2>&1;
84 echo
85
86 if [ -n "$TRUNK" ]; then
87   I18NFILE=i18n_trunk.inc;
88 else
89   I18NFILE=i18n.inc;
90 fi
91
92 # make sure things are clean
93 rm -f i18n.inc;
94 svn revert $FARM/$I18NFILE;
95
96 echo Running make i18n.inc...
97 make i18n.inc  >/dev/null 2>&1;
98 if [ -n "$TRUNK" ]; then
99   mv -f i18n.inc i18n_trunk.inc
100 fi
101
102 if diff -w -q $I18NFILE $FARM/$I18NFILE >/dev/null 2>&1; then
103   echo No string differences found.
104   # So we will revert the changes to po files, which are probably
105   # just dates and such.
106   if [ "$VCS" = "svn" ]; then
107     svn revert *.po;
108   else
109     git checkout *.po;
110   fi
111   exit 0;
112 fi
113
114 # So there are differences.
115
116 if [ -z "$COMMIT" ]; then
117   echo "Differences found!";
118   diff -w $I18NFILE $FARM/$I18NFILE | less;
119   if [ "$VCS" = "svn" ]; then
120     svn revert *.po;
121   else
122     git checkout *.po;
123   fi
124   exit 0;
125 fi
126
127 if [ "$VCS" = "svn" ]; then
128   $DEBUG svn ci *.po;
129 else
130   $DEBUG git commit *.po -m "Remerge strings.";
131   $DEBUG git svn dcommit;
132 fi
133
134 echo
135
136 if ! cd $FARM; then
137   echo "Unable to cd to $FARM!";
138   exit 1;
139 fi
140
141 echo Updating the www-user tree...
142 # note that we're assuming this one is svn.
143 svn up;
144
145 echo Moving $I18NFILE...;
146 mv $LYXROOT/po/$I18NFILE .;
147
148 echo Committing...;
149 $DEBUG svn commit -m "* $I18NFILE: update stats" $I18NFILE;
150
151 if [ -n "$NOTSAFE" ]; then
152   echo
153   echo "Your LyX tree was not clean.";
154   echo "Your will need to push changes to po files manually."
155 fi