Android Tutorial [B4X] Localizator with CSV files

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.
B4X:
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:
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
    11.6 KB · Views: 532
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
(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.)
No. CurrentIndex is a global variable and it will be 1 after the first call to ReadLine:
B4X:
Dim count As Int = ReadLine(Input, Null, True, SeparatorChar)
If SkipFirstRow = False Then CurrentIndex = 0 '<--- go back to the headers line if SkipFirstRow = False
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…