diff options
author | Unknwon <u@gogs.io> | 2017-02-18 15:00:11 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-02-18 15:00:11 -0500 |
commit | 685737b8168ea4cf23410d5adf83fcb0ed581467 (patch) | |
tree | 73c1a576b4fa7005971b87bc61fec5bd2ab15ea7 /cmd | |
parent | 5d766bc4d6d7a2a876b5f769b7dc85d3dfd8f7bf (diff) |
locale: add Ukrainian support
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/import.go | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/cmd/import.go b/cmd/import.go index 482361b6..e575736a 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -5,6 +5,8 @@ package cmd import ( + "bufio" + "bytes" "fmt" "os" "path/filepath" @@ -59,6 +61,10 @@ func runImportLocale(c *cli.Context) error { now := time.Now() + line := make([]byte, 0, 100) + badChars := []byte(`="`) + escapedQuotes := []byte(`\"`) + regularQuotes := []byte(`"`) // Cut out en-US. for _, lang := range setting.Langs[1:] { name := fmt.Sprintf("locale_%s.ini", lang) @@ -68,10 +74,35 @@ func runImportLocale(c *cli.Context) error { continue } - if err := com.Copy(source, target); err != nil { - return fmt.Errorf("Copy file: %v", err) + // Crowdin surrounds double quotes for strings contain quotes inside, + // this breaks INI parser, we need to fix that. + sr, err := os.Open(source) + if err != nil { + return fmt.Errorf("Open: %v", err) } + tw, err := os.Create(target) + if err != nil { + if err != nil { + return fmt.Errorf("Open: %v", err) + } + } + + scanner := bufio.NewScanner(sr) + for scanner.Scan() { + line = scanner.Bytes() + idx := bytes.Index(line, badChars) + if idx > -1 && line[len(line)-1] == '"' { + // We still want the "=" sign + line = append(line[:idx+1], line[idx+2:len(line)-1]...) + line = bytes.Replace(line, escapedQuotes, regularQuotes, -1) + } + tw.Write(line) + tw.WriteString("\n") + } + sr.Close() + tw.Close() + // Modification time of files from Crowdin often ahead of current, // so we need to set back to current. os.Chtimes(target, now, now) |