From 4616734d3364f5eaeb7dc82c8f19241477125dc6 Mon Sep 17 00:00:00 2001 From: slubek Date: Fri, 13 Feb 2004 00:05:57 +0000 Subject: [PATCH] Fixed version. And safer, I hope. Please, test it. --- lang/synch | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/lang/synch b/lang/synch index a0306d61..7d4e9fcd 100755 --- a/lang/synch +++ b/lang/synch @@ -3,21 +3,19 @@ # english translation using chriskl's langcheck utility. # It doesn't translate strings, only inserts english versions # to proper positions and deletes removed. And it doesn't -# synchronize commented lines. Use it at your own risk! +# synchronize commented lines. # You need to have GNU ed installed. # # Usage: synch # # is the filename without the .php extension +# +# WARNING! +# I've tested it and it seems working fine. But I've not tested +# all combinations of input files lines, so use it at your own +# risk! +# -# WARNING: THE SYNCH SCRIPT IS BUGGY. IT MAY DELETE SOME -# GOOD TRANSLATIONS. COMMENT OUT THE LINES BELOW IF YOU -# KNOW WHAT YOU ARE DOING. - -echo "The synch script has been found to be buggy. We recommend using"; -echo "langcheck instead. For more information, view the synch source code."; -exit - if [ -z $1 ] ; then echo "You must tell me which language I should synchronize." echo -e "for example: \n\t$0 polish" @@ -29,6 +27,9 @@ if [ ! -f $1.php ] ; then exit fi +echo "Making backup of $1.php" +cp $1.php $1.php.old + php langcheck $1 | awk ' function grep_n(what, where, n, ln) { @@ -45,6 +46,16 @@ function grep_n(what, where, n, ln) { return ln; } +function add_line(nr, where, what) { + print nr"a\n"what"\n.\nw" | "/bin/ed -s "where + system ("/bin/sync") +} + +function del_line(nr, where) { + print nr"d\nw" | "/bin/ed -s "where + system ("/bin/sync") +} + BEGIN { line=1 } # Analyse of "php langcheck language" output. # Chris - please, do not change those texts in langcheck :-) @@ -57,26 +68,17 @@ BEGIN { line=1 } # a[2] = strxxxxx # Adding a line if(oper=="+") { - line = grep_n("\x27"a[2]"\x27", src) - 1; + line = grep_n("\x27"a[2]"\x27", src) ; if (line>0) { - print line"a"; - # New lines got no "\t" at beginning because they are not - # translated yet, so it will help translator to find them - print $0; - print "."; + add_line(line-1, trg, $0) } } # Deleting a line if(oper=="-") { - line = grep_n("\x27"a[2]"\x27", trg); + line = grep_n("\x5B\x27"a[2]"\x27\x5D", trg); if (line>0) { - print line"d" + del_line(line, trg) } } } -END { - # Writing changes after every edit - print "w"; - } -' | ed $1.php - +' -- 2.39.5