This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes


I have a CSV file containing a certain number of keys associated to a dialog in game:

For example:

TUTO_1,First line in English, First line in french
TUTO_2,Second line in English, Second line in french 

Right now I load the dialog as follows in my code:

var dialog = [

If later I add TUTO_3 in the file I would like to fill this list aromatically. So I was wondering is it possible to get all possible keys from a CSV translation file so I can iterate over them ?

I'm thinking of something like this:

var dialog = []
for key in tr.get_keys(): 
    dialog .append(tr(key))

Any suggestions on how to proceed ?

Godot version 3.2.3
in Engine by (36 points)

1 Answer

+1 vote
Best answer

I did not know how translations worked :-p

I came up with this code ... uncomment save to create the CSV first if you want to create the file first.

extends Control

var CSV:PoolStringArray = [
    "TUTO_1,First line in English, First line in french",
    "TUTO_2,Second line in English, Second line in french" 

func _ready():
    var data = load_csv()
    var header
    var keys:Array = []
    for d in data:
        if header == null:
            header = d

func save(content):
    var file ="res://98940/98940.csv", File.WRITE)

func load_csv() -> Array:
    var data:Array = []
    var file ="res://98940/98940.csv", File.READ)
    while not file.eof_reached():
        var line = file.get_csv_line()
    return data
by (646 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.