summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/lang.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/lang.tcl')
-rwxr-xr-xSQLiteStudio3/lang.tcl358
1 files changed, 165 insertions, 193 deletions
diff --git a/SQLiteStudio3/lang.tcl b/SQLiteStudio3/lang.tcl
index 52661f3..cafe27a 100755
--- a/SQLiteStudio3/lang.tcl
+++ b/SQLiteStudio3/lang.tcl
@@ -1,9 +1,9 @@
#!/usr/bin/env tclsh
proc usage {} {
- puts "$::argv0 (add|remove) <lang_name>"
- puts "$::argv0 add_plugin <plugin name>"
- puts "$::argv0 (update|release|status)"
+ puts "$::argv0 add_lang <lang_name>"
+ puts "$::argv0 add_plugin <plugin>"
+ puts "$::argv0 status"
}
lassign $argv op lang
@@ -40,6 +40,16 @@ proc countstrings {data search} {
set count
}
+proc findLangs {} {
+ set langs [list]
+ foreach f [find coreSQLiteStudio "*.ts"] {
+ set lang [lindex [regexp -inline {[^_]*_(\w+(\w+)?).ts$} $f] 1]
+ if {$lang == ""} continue
+ lappend langs $lang
+ }
+ return $langs
+}
+
proc scanLangs {} {
set langs [dict create]
foreach f [find .. "*.ts"] {
@@ -64,211 +74,173 @@ proc scanLangs {} {
return $langs
}
-switch -- $op {
- "update" - "release" {
- if {$argc != 1} {
- usage
- exit 1
+proc finalTsFix {f} {
+ set fd [open $f r]
+ set data [read $fd]
+ close $fd
+
+ set parts [lsort -unique [regexp -all -inline -- {>[^<]*\"[^<]*<} $data]]
+ foreach part $parts {
+ set fixedPart [string map [list \" "&quot;"] $part]
+ set data [string trim [string map [list $part $fixedPart] $data]]
}
+
+ set data [string trim [string map [list ' "&apos;" " " "&#xa0;"] $data]]
+
+ set fd [open $f w+]
+ puts $fd $data
+ close $fd
+}
- set files [list]
- foreach p [list coreSQLiteStudio guiSQLiteStudio sqlitestudio sqlitestudiocli] {
- lappend files $p/$p.pro
- }
+switch -- $op {
+ "update" {
+ if {$argc != 1} {
+ usage
+ exit 1
+ }
- foreach d [glob -directory ../Plugins -tails -nocomplain *] {
- if {![file isdirectory ../Plugins/$d]} continue
- lappend files ../Plugins/$d/$d.pro
- }
-
- foreach f $files {
- catch {
- if {$op == "update"} {
- exec lupdate $f
- } else {
- #exec lrelease $f $::ERR_NULL
- exec lrelease $f
+ set files [list]
+ foreach p [list coreSQLiteStudio guiSQLiteStudio sqlitestudio sqlitestudiocli] {
+ lappend files $p/$p.pro
+ }
+
+ foreach d [glob -directory ../Plugins -tails -nocomplain *] {
+ if {![file isdirectory ../Plugins/$d]} continue
+ lappend files ../Plugins/$d/$d.pro
}
- } res
- if {$op == "release"} {
- puts $res
- } else {
- foreach line [split $res \n] {
- if {[string first Q_OBJECT $line] > -1} {
- puts $line
- }
- if {[regexp -- {^.*\w+\.ts.*$} $line]} {
- puts -nonewline [lindex [regexp -inline -- {^.*"([\w\/\\\.]+\.ts)".*$} $line] 1]
- puts -nonewline ": "
- }
- if {[regexp -- {^.*\d+[^\d]+\(\d+[^\d]+\d+.*\).*$} $line]} {
- puts -nonewline [lindex [regexp -inline -- {\S+.*} $line] 0]
- set new [lindex [regexp -inline -- {^.*\d+[^\d]+(\d+)[^\d]+\d+.*$} $line] 1]
- if {$new > 0} {
- puts -nonewline " <- !!!!!!!!!!!"
+
+ foreach f $files {
+ catch {
+ puts "updating $f"
+ exec lupdate $f
+ } res
+ # foreach line [split $res \n] {
+ # if {[string first Q_OBJECT $line] > -1} {
+ # puts $line
+ # }
+ # if {[regexp -- {^.*\w+\.ts.*$} $line]} {
+ # puts -nonewline [lindex [regexp -inline -- {^.*"([\w\/\\\.]+\.ts)".*$} $line] 1]
+ # puts -nonewline ": "
+ # }
+ # if {[regexp -- {^.*\d+[^\d]+\(\d+[^\d]+\d+.*\).*$} $line]} {
+ # puts -nonewline [lindex [regexp -inline -- {\S+.*} $line] 0]
+ # set new [lindex [regexp -inline -- {^.*\d+[^\d]+(\d+)[^\d]+\d+.*$} $line] 1]
+ # if {$new > 0} {
+ # puts -nonewline " <- !!!!!!!!!!!"
+ # }
+ # puts ""
+ # }
+ # }
+ }
+
+ set tsFiles [list]
+ foreach d [list coreSQLiteStudio guiSQLiteStudio sqlitestudio sqlitestudiocli] {
+ lappend tsFiles {*}[glob -directory $d/translations -nocomplain *.ts]
+ }
+
+ foreach d [glob -directory ../Plugins -tails -nocomplain *] {
+ if {![file isdirectory ../Plugins/$d/translations]} continue
+ lappend tsFiles {*}[glob -directory ../Plugins/$d/translations -nocomplain *.ts]
+ }
+
+ foreach f $tsFiles {
+ if {[catch {
+ puts "formatting $f"
+ exec xmllint --format -o $f $f
+ finalTsFix $f
+ } res]} {
+ puts $res
}
- puts ""
- }
}
- }
- }
}
"status" {
- set langs [scanLangs]
- foreach k [dict keys $langs] {
- set lang [dict get $langs $k]
- set tr [dict get $lang translated]
- set untr [dict get $lang untranslated]
- set all [expr {$tr + $untr}]
- if {$all == 0} continue
-
- set perc [expr {round(double($tr)/$all * 1000)/10.0}]
-
- set lang [string tolower $lang]
- puts "$k - ${perc}% ($tr / $all)"
- }
+ set langs [scanLangs]
+ foreach k [dict keys $langs] {
+ set lang [dict get $langs $k]
+ set tr [dict get $lang translated]
+ set untr [dict get $lang untranslated]
+ set all [expr {$tr + $untr}]
+ if {$all == 0} continue
+
+ set perc [expr {round(double($tr)/$all * 1000)/10.0}]
+
+ set lang [string tolower $lang]
+ puts "$lang - ${perc}% ($tr / $all)"
+ }
}
"add_plugin" {
- if {$argc != 2} {
- usage
- exit 1
- }
-
- set plug [lindex $argv 1]
- set plugPro ../Plugins/$plug/$plug.pro
- if {![file exists $plugPro]} {
- puts "$plugPro does not exist."
- exit 1
- }
-
- set fd [open ../Plugins/CsvImport/CsvImport.pro r]
- set data [read $fd]
- close $fd
-
- set langs [list]
- set trData "\nTRANSLATIONS += "
- foreach {all lang} [regexp -inline -all -- {CsvImport_(\w+)\.ts} $data] {
- append trData "\\\n\t\t${plug}_$lang.ts"
- lappend langs $lang
- }
- append trData "\n"
-
- set fd [open $plugPro a+]
- puts $fd $trData
- close $fd
- puts "Added translation languages for plugin $plug:\n[join $langs \n]"
+ if {$argc != 2} {
+ usage
+ exit 1
+ }
+
+ set plug [lindex $argv 1]
+ set plugPro ../Plugins/$plug/$plug.pro
+ if {![file exists $plugPro]} {
+ puts "$plugPro does not exist."
+ exit 1
+ }
+
+ if {![file exists ../Plugins/$plug/translations]} {
+ file mkdir ../Plugins/$plug/translations
+ }
+
+ set plugTs ../Plugins/$plug/translations/$plug.ts
+ if {![file exists $plugTs]} {
+ catch {
+ exec lupdate-pro $plugPro -ts $plugTs
+ }
+ if {![file exists $plugTs]} {
+ puts "Failed to create $plugTs."
+ exit 1
+ }
+ }
+
+ foreach lang [findLangs] {
+ set plugTs ../Plugins/$plug/translations/${plug}_${lang}.ts
+ if {![file exists $plugTs]} {
+ catch {exec lupdate-pro $plugPro -ts $plugTs}
+ }
+ }
}
- "add" - "remove" {
- if {$argc != 2} {
- usage
- exit 1
- }
-
- foreach p [list coreSQLiteStudio guiSQLiteStudio sqlitestudio sqlitestudiocli] {
- # pro file
- set fd [open $p/$p.pro r]
- set data [read $fd]
- close $fd
-
- set ts "translations/${p}_$lang.ts"
- if {$op == "add" && [string first $ts $data] == -1} {
- set data [string map [list "TRANSLATIONS += " "TRANSLATIONS += $ts \\\n\t\t"] $data]
- } elseif {$op == "remove" && [string first $ts $data] > -1} {
- regsub -- "$ts\\s*(\\\\)?\n\\s*" $data "" data
- } else {
- continue
- }
-
- set fd [open $p/$p.pro w+]
- puts $fd $data
- close $fd
-
- puts "Updated $p.pro"
- }
-
- foreach p [list coreSQLiteStudio guiSQLiteStudio sqlitestudio sqlitestudiocli] {
- # qrc file
- set fd [open $p/$p.qrc r]
- set data [read $fd]
- close $fd
-
- set qm "translations/${p}_$lang.qm"
- if {$op == "add" && [string first $qm $data] == -1} {
- set data [string map [list "<qresource prefix=\"/msg\">" "<qresource prefix=\"/msg\">\n <file>$qm</file>"] $data]
- } elseif {$op == "remove" && [string first $qm $data] > -1} {
- regsub -- "\\s*$qm\\s*\n" $data "" data
- } else {
- continue
- }
-
- set fd [open $p/$p.qrc w+]
- puts $fd $data
- close $fd
-
- puts "Updated $p.qrc"
- }
-
- foreach d [glob -directory ../Plugins -tails -nocomplain *] {
- if {![file isdirectory ../Plugins/$d]} continue
-
- # pro file
- set fd [open ../Plugins/$d/$d.pro r]
- set data [read $fd]
- close $fd
+ "add_lang" {
+ if {$argc != 2} {
+ usage
+ exit 1
+ }
- if {[string first "TRANSLATIONS +=" $data] == -1} continue
+ foreach d [list coreSQLiteStudio guiSQLiteStudio sqlitestudio sqlitestudiocli] {
+ set pro $d/$d.pro
+ set ts "$d/translations/${d}_$lang.ts"
+ if {![file exists $ts]} {
+ catch {exec lupdate-pro $pro -ts $ts}
+ }
+ }
- set ts "${d}_$lang.ts"
- if {$op == "add" && [string first $ts $data] == -1} {
- set data [string map [list "TRANSLATIONS += " "TRANSLATIONS += $ts \\\n\t\t"] $data]
- } elseif {$op == "remove" && [string first $ts $data] > -1} {
- regsub -- "$ts\\s*(\\\\)?\n\\s*" $data "" data
- } else {
- continue
- }
-
- set fd [open ../Plugins/$d/$d.pro w+]
- puts $fd $data
- close $fd
-
- puts "Updated $d.pro"
+ foreach d [glob -directory ../Plugins -tails -nocomplain *] {
+ if {![file isdirectory ../Plugins/$d]} continue
+ set pro ../Plugins/$d/$d.pro
+ set ts "../Plugins/$d/translations/${d}_$lang.ts"
+ if {![file exists $ts]} {
+ catch {exec lupdate-pro $pro -ts $ts}
+ }
+ }
}
-
- foreach d [glob -directory ../Plugins -tails -nocomplain *] {
- # qrc file
- if {![file isdirectory ../Plugins/$d]} continue
- if {[file exists ../Plugins/$d/$d.qrc]} {
- set fname ../Plugins/$d/$d.qrc
- set fnameOnly $d.qrc
- } elseif {[file exists ../Plugins/$d/[string tolower $d].qrc]} {
- set fname ../Plugins/$d/[string tolower $d].qrc
- set fnameOnly [string tolower $d].qrc
- } else {
- continue
- }
-
- set fd [open $fname r]
- set data [read $fd]
- close $fd
-
- if {[string first "<qresource prefix=\"/msg\">" $data] == -1} continue
-
- set qm "${d}_$lang.qm"
- if {$op == "add" && [string first $qm $data] == -1} {
- set data [string map [list "<qresource prefix=\"/msg\">" "<qresource prefix=\"/msg\">\n <file>$qm</file>"] $data]
- } elseif {$op == "remove" && [string first $qm $data] > -1} {
- regsub -- "\\s*$qm\\s*\n" $data "" data
- } else {
- continue
- }
-
- set fd [open $fname w+]
- puts $fd $data
- close $fd
-
- puts "Updated $fnameOnly"
+ "validate" {
+ set ok 0
+ set fail 0
+ foreach f [find .. "*.ts"] {
+ catch {exec xmllint --noout --schema ts.xsd $f} out
+ set parts [split $out " "]
+ if {[lindex $parts 1] != "validates"} {
+ puts "$f: $out"
+ incr fail
+ } else {
+ incr ok
+ }
+ }
+ puts "Ok: $ok, Failed: $fail"
}
- }
default {
usage
}