Feb 27, 2020 Replies: 2 For the first time I try to make my apps multilingual and found this very useful helper. But I prefer to use CSV files (not excel) for the translations. So I combined it with this CSV-Parser. (By the way: Please check line 43 in the original CSVParser Class. I think, if you want to skip first row, it should be "CurrentIndex = 1", not 0.) Now in the tool, you choose a CSV file (by default separated with ';', but you can change it in the code. The rest is the same as in the original tool. Code: Copy Private Sub BuildDatabaseFromCSV (Csv As String, Output As String) Dim SeparatorChar As Char = ";" Dim parser As CSVParser parser.Initialize Dim table As List = parser.Parse(File.ReadString(Csv, ""), SeparatorChar, False) '... End Sub The CSV file should be utf-8 encoded. If not, convert the encoding in the file or after File.ReadString in the code like that: B4X: Copy Sub ConvertTextencoding(text As String, fromEncoding As String, toEncoding As String) As String Dim b() As Byte = text.getbytes(fromEncoding) 'Encoding: "UTF-8", "iso-8859-1", ... Return BytesToString( b, 0, b.Length, toEncoding) End Sub Update: Now, after praxis test with google docs (table - download file as csv), had to correct a bug in line 100 (Main) and now it is "," as default SeparatorChar. Attachments B4XLocalizatorCSVTool.zip B4XLocalizatorCSVTool.zip 11.6 KB · Views: 937 Last edited: Mar 1, 2020 Click to expand...
For the first time I try to make my apps multilingual and found this very useful helper. But I prefer to use CSV files (not excel) for the translations. So I combined it with this CSV-Parser. (By the way: Please check line 43 in the original CSVParser Class. I think, if you want to skip first row, it should be "CurrentIndex = 1", not 0.) Now in the tool, you choose a CSV file (by default separated with ';', but you can change it in the code. The rest is the same as in the original tool. Code: Copy Private Sub BuildDatabaseFromCSV (Csv As String, Output As String) Dim SeparatorChar As Char = ";" Dim parser As CSVParser parser.Initialize Dim table As List = parser.Parse(File.ReadString(Csv, ""), SeparatorChar, False) '... End Sub The CSV file should be utf-8 encoded. If not, convert the encoding in the file or after File.ReadString in the code like that: B4X: Copy Sub ConvertTextencoding(text As String, fromEncoding As String, toEncoding As String) As String Dim b() As Byte = text.getbytes(fromEncoding) 'Encoding: "UTF-8", "iso-8859-1", ... Return BytesToString( b, 0, b.Length, toEncoding) End Sub Update: Now, after praxis test with google docs (table - download file as csv), had to correct a bug in line 100 (Main) and now it is "," as default SeparatorChar.
Erel B4X founder Staff member Licensed User Longtime User Feb 28, 2020 #2 skrjabin said: (By the way: Please check line 43 in the original CSVParser Class. I think, if you want to skip first row, it should be "CurrentIndex = 1", not 0.) Click to expand... No. CurrentIndex is a global variable and it will be 1 after the first call to ReadLine: Code: Copy Dim count As Int = ReadLine(Input, Null, True, SeparatorChar) If SkipFirstRow = False Then CurrentIndex = 0 '<--- go back to the headers line if SkipFirstRow = False
skrjabin said: (By the way: Please check line 43 in the original CSVParser Class. I think, if you want to skip first row, it should be "CurrentIndex = 1", not 0.) Click to expand... No. CurrentIndex is a global variable and it will be 1 after the first call to ReadLine: Code: Copy Dim count As Int = ReadLine(Input, Null, True, SeparatorChar) If SkipFirstRow = False Then CurrentIndex = 0 '<--- go back to the headers line if SkipFirstRow = False
Cadenzo Active Member Licensed User Longtime User Feb 28, 2020 #3 CurrentIndex is a global variable and it will be 1 after the first call to ReadLine Click to expand... OK, I see, removed it.
CurrentIndex is a global variable and it will be 1 after the first call to ReadLine Click to expand... OK, I see, removed it.