File: checklangs.tcl

package info (click to toggle)
scid 1%3A4.3.0.cvs20120311-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 24,232 kB
  • sloc: tcl: 135,238; cpp: 47,810; ansic: 5,339; sh: 2,882; python: 278; makefile: 105; perl: 86
file content (124 lines) | stat: -rwxr-xr-x 3,189 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/tclsh
###
### checklangs.tcl
###

# This script is not part of the Scid source code; it is a standalone
# program which verifies that every language file has the same
# translation commands in the same order as english.tcl.

array set codes {
  czech C
  deutsch D
  francais F
  greek G
  hungary H
  italian I
  nederlan N
  norsk O
  polish P
  portbr B
  russian R
  serbian Y
  spanish S
  swedish W
  catalan K
  suomi U
  greek G
}

set languages {czech deutsch francais hungary italian nederlan norsk polish
  portbr spanish swedish serbian russian catalan suomi greek
}

################################################################################
# handle multiple lines statements and keep only lines with
# menuText translate helpMsg
proc multiLines {tmp} {
  set data {}
  for {set i 0} {$i < [llength $tmp]} {incr i} {
    set line [lindex $tmp $i]
    if {[string first "\{" $line] != -1 && [string first "\}" $line] == -1 } {
      incr i
      while { [string first "\}" [lindex $tmp $i] ] == -1  && $i < [llength $tmp] } {
        append line "\n[lindex $tmp $i]"
        incr i
      }
      append line "\n[lindex $tmp $i]"
    }
    lappend data $line
  }
  set strippedData {}
  
  foreach line $data {
    if { [catch {set command [lindex $line 0]} ] } {
      continue
    } else {
      if { $command == "menuText" || $command == "translate" || $command == "helpMsg" } {
        lappend strippedData $line
      }
    }
  }
  
  return $strippedData
}
################################################################################
proc checkfile {code langfile} {
  # Read this language file and the english file:
  
  set f [open english.tcl r]
  set data [read $f]
  close $f
  set tmp [split $data "\n"]
  set englishData [multiLines $tmp]
  
  set f [open $langfile.tcl r]
  set data [read $f]
  close $f
  set tmp [split $data "\n"]
  set langData [multiLines $tmp]
  
  set langNames {}
  
  foreach line $langData {
    if { [catch {set command [lindex $line 0]} ] } {
      # puts "problem->$line"
      continue
    }
    set lang [lindex $line 1]
    set name [lindex $line 2]
    if {$lang == $code  &&  ($command == "menuText" || $command == "translate" || $command == "helpMsg")} {
      lappend langNames $command:$name
    }
  }
  
  set lastMatch -1
  foreach line $englishData {
    if { [catch {set command [lindex $line 0]} ] } { continue }
    set lang [lindex $line 1]
    set name [lindex $line 2]
    if {$lang == "E"  &&  ($command == "menuText" || $command == "translate" || $command == "helpMsg")} {
      set thisMatch [lsearch -exact $langNames $command:$name]
      if {$thisMatch < 0} {
        puts "$langfile - MISSING: $name"
      } else {
        if {$thisMatch != $lastMatch + 1} {
          puts "$langfile - OUT OF ORDER: $command $lang $name"
        }
        set lastMatch $thisMatch
      }
    }
  }
}
################################################################################

if {[llength $argv] == 0} { set argv $languages }

foreach language $argv {
  if {[info exists codes($language)]} {
    checkfile $codes($language) $language
  } else {
    puts "No such language file: $language"
  }
}