Skip to content

Commit d7eebea

Browse files
committed
Add project files
1 parent 5266470 commit d7eebea

File tree

8 files changed

+18333
-0
lines changed

8 files changed

+18333
-0
lines changed

Assets/KO 105 tr.srt

Lines changed: 6613 additions & 0 deletions
Large diffs are not rendered by default.

Assets/KO 107 tr.srt

Lines changed: 2512 additions & 0 deletions
Large diffs are not rendered by default.

Assets/Translated-eng - 105.srt

Lines changed: 6613 additions & 0 deletions
Large diffs are not rendered by default.

Assets/Translated-eng.srt

Lines changed: 2512 additions & 0 deletions
Large diffs are not rendered by default.

Main.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strings"
8+
"unicode"
9+
10+
translator "github.com/Conight/go-googletrans"
11+
)
12+
13+
func isNumber(s string) bool {
14+
for _, c := range s {
15+
if !unicode.IsDigit(c) {
16+
return false
17+
}
18+
}
19+
20+
return true
21+
}
22+
23+
func CreateFile(path string) *os.File {
24+
f, err := os.Create(path)
25+
if err != nil {
26+
panic(err)
27+
}
28+
29+
return f
30+
}
31+
32+
func main() {
33+
t := translator.New()
34+
35+
fmt.Println("Welcome")
36+
input := bufio.NewReader(os.Stdin)
37+
38+
fmt.Print("Input source file: ")
39+
filePath, _ := input.ReadString('\n')
40+
41+
// file, _ := os.Open("Assets/KO 105 tr.srt")
42+
file, _ := os.Open(filePath)
43+
44+
fmt.Print("Input destination file: ")
45+
outPath, _ := input.ReadString('\n')
46+
outFile := CreateFile(outPath)
47+
//outFile := CreateFile("Assets/Translated-eng - 105.srt")
48+
49+
scanner := bufio.NewScanner(file)
50+
for scanner.Scan() {
51+
line := scanner.Text()
52+
var outBuf string
53+
54+
if !isNumber(line) && !strings.Contains(line, "-->") && line != "\n" {
55+
translated, err := t.Translate(line, "tr", "en")
56+
if err != nil {
57+
panic(err)
58+
}
59+
outBuf = translated.Text + "\n"
60+
} else {
61+
outBuf = line + "\n"
62+
}
63+
64+
outFile.WriteString(outBuf)
65+
fmt.Print(outBuf)
66+
}
67+
68+
file.Close()
69+
outFile.Close()
70+
71+
fmt.Println("\nTranslation has concluded!")
72+
fmt.Scanln()
73+
}

SubtitleTranslator.code-workspace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"folders": []
3+
}

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module SubtitleTranslator
2+
3+
go 1.18
4+
5+
require github.com/Conight/go-googletrans v0.2.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/Conight/go-googletrans v0.2.2 h1:MCx2h691F/giWR4X/dXBZxNixHO7vN2vw/wz+VO/XL8=
2+
github.com/Conight/go-googletrans v0.2.2/go.mod h1:vl4tB0jWplJ1ZsEul86jXSMUrM+llD1qHK2XbjVBwvk=

0 commit comments

Comments
 (0)