@@ -2,26 +2,37 @@ package main
2
2
3
3
import (
4
4
"LargeCsvReader/widgets"
5
+ "embed"
5
6
"encoding/csv"
6
7
"fyne.io/fyne/v2"
7
8
"fyne.io/fyne/v2/app"
8
9
"fyne.io/fyne/v2/container"
9
10
"fyne.io/fyne/v2/dialog"
11
+ "fyne.io/fyne/v2/lang"
10
12
"fyne.io/fyne/v2/layout"
11
13
"fyne.io/fyne/v2/storage"
12
14
"fyne.io/fyne/v2/widget"
13
15
"io"
14
16
"os"
15
17
)
16
18
19
+ //go:embed translation
20
+ var translations embed.FS
21
+
17
22
func showPreviewWindow (filePath string , fyneApp fyne.App ) {
18
- window := fyneApp .NewWindow (" Preview" )
23
+ window := fyneApp .NewWindow (lang . X ( "app.preview" , " Preview") )
19
24
window .Resize (fyne .NewSize (640 , 480 ))
20
25
21
26
typeToCharMap := map [string ]rune {
22
- "Comma" : ',' ,
23
- "Semicolon" : ';' ,
24
- "Tab" : '\t' ,
27
+ lang .X ("app.separator.comma" , "Comma" ): ',' ,
28
+ lang .X ("app.separator.semicolon" , "Semicolon" ): ';' ,
29
+ lang .X ("app.separator.tab" , "Tab" ): '\t' ,
30
+ }
31
+ separatorOptions := make ([]string , len (typeToCharMap ))
32
+ i := 0
33
+ for key := range typeToCharMap {
34
+ separatorOptions [i ] = key
35
+ i ++
25
36
}
26
37
27
38
file , err := os .Open (filePath )
@@ -31,7 +42,7 @@ func showPreviewWindow(filePath string, fyneApp fyne.App) {
31
42
var csvFile * csv.Reader
32
43
rows := make ([][]string , 5 )
33
44
34
- previewText := widget .NewLabel (" Preview" )
45
+ previewText := widget .NewLabel (lang . X ( "app.preview" , " Preview") )
35
46
previewText .Hide ()
36
47
37
48
tableContainer := container .NewStack ()
@@ -54,7 +65,7 @@ func showPreviewWindow(filePath string, fyneApp fyne.App) {
54
65
cell .SetText (rows [id.Row ][id.Col ])
55
66
cell .OnRightClick = func (event * fyne.PointEvent ) {
56
67
items := []* fyne.MenuItem {
57
- fyne .NewMenuItem (" Copy" , func () {
68
+ fyne .NewMenuItem (lang . X ( "app.copy_to_clipboard" , " Copy") , func () {
58
69
window .Clipboard ().SetContent (cell .Text )
59
70
}),
60
71
}
@@ -69,7 +80,7 @@ func showPreviewWindow(filePath string, fyneApp fyne.App) {
69
80
}
70
81
71
82
var loadMoreButton * widget.Button
72
- loadMoreButton = widget .NewButton (" Load more" , func () {
83
+ loadMoreButton = widget .NewButton (lang . X ( "app.load_more_button" , " Load more") , func () {
73
84
for range 5 {
74
85
line , err := csvFile .Read ()
75
86
if err == io .EOF {
@@ -87,7 +98,7 @@ func showPreviewWindow(filePath string, fyneApp fyne.App) {
87
98
})
88
99
loadMoreButton .Hide ()
89
100
90
- separatorSelect := widget .NewSelect ([] string { "Comma" , "Semicolon" , "Tab" } , func (selected string ) {
101
+ separatorSelect := widget .NewSelect (separatorOptions , func (selected string ) {
91
102
csvFile = csv .NewReader (file )
92
103
csvFile .LazyQuotes = true
93
104
csvFile .Comma = typeToCharMap [selected ]
@@ -125,7 +136,7 @@ func showPreviewWindow(filePath string, fyneApp fyne.App) {
125
136
126
137
mainContainer := container .NewBorder (
127
138
container .NewVBox (
128
- widget .NewLabel (" Separator" ),
139
+ widget .NewLabel (lang . X ( "app.separator" , " Separator") ),
129
140
separatorSelect ,
130
141
lineSeparator1 ,
131
142
container .NewHBox (
@@ -153,7 +164,12 @@ func showPreviewWindow(filePath string, fyneApp fyne.App) {
153
164
154
165
func main () {
155
166
fyneApp := app .NewWithID ("1af17320-d9ef-4d2b-aae1-8226b14a177a" )
156
- window := fyneApp .NewWindow ("Large CSV Reader" )
167
+ err := lang .AddTranslationsFS (translations , "translation" )
168
+ if err != nil {
169
+ panic (err )
170
+ }
171
+
172
+ window := fyneApp .NewWindow (lang .X ("app.title" , "Large CSV Reader" ))
157
173
window .Resize (fyne .NewSize (640 , 480 ))
158
174
window .SetMaster ()
159
175
@@ -166,11 +182,11 @@ func main() {
166
182
167
183
window .SetContent (container .NewVBox (
168
184
container .NewCenter (
169
- widget .NewLabel (" Using the button below choose a CSV you want to open" ),
185
+ widget .NewLabel (lang . X ( "app.choose_csv_button.description" , " Using the button below choose a CSV you want to open") ),
170
186
),
171
187
container .New (
172
188
layout .NewCustomPaddedLayout (8 , 0 , 32 , 32 ),
173
- widget .NewButton (" Open CSV" , func () {
189
+ widget .NewButton (lang . X ( "app.choose_csv_button" , " Open CSV") , func () {
174
190
openDialog .Show ()
175
191
}),
176
192
),
0 commit comments