remram44 / pybabel-godot

Plugin for Babel to support Godot scene files (.tscn)
Other
14 stars 11 forks source link

Matching array of strings #6

Closed h0lley closed 2 years ago

h0lley commented 3 years ago

This time I have something I'd really love to see. ;) I have GDScripts that export variables like this:

export(Array, String, MULTILINE) var dialogue_text

This enables me to create any number of dialogue text boxes neatly from the inspector. The result is then saved in the scene file like this:

dialogue_text = [ "Some text A", "Some text B" ]

multiline example:

dialogue_text = [ "Some text
AAA bbb
CCC ddd", "Some text
EEE ddd
FFF ggg" ]

but it is not picked up by pybabel with -k dialogue_text. It would be best if pybabel could add the strings from the array as individual entries to the POT.

though I fear this is similarly out of scope for this project than the issue with the escaped script?

remram44 commented 3 years ago

This could probably be supported, though there is no good way to distinguish the multiple entries with this setup. Numbering them might cause headaches to translators when new entries get added/removed.

h0lley commented 3 years ago

I've got this to work with both arrays and multiline strings. keep in mind the code is probably improvable as I have hardly any experience with python, and it could definitely use some more testing.

here's some scenarios it attempts to cover:

keyword = "hello"

keyword = "hello
second line
third line"

keyword = ["first item", "second item"]

keyword = ["first
item", "second item"]

keyword = ["first
item", "second item", "third
item"]

keyword = ["first
item", "second item", "third item", "forth
item"]

keyword = ["first
item", "second
item", "third
item", "forth
item"]
myin142 commented 2 years ago

Is this already in the newest release?

remram44 commented 2 years ago

This has not been implemented no.

myin142 commented 2 years ago

Oh I thought the pull request was merged. Did not noticed that it was just closed. Did his implementation not work?

h0lley commented 2 years ago

Oh I thought the pull request was merged. Did not noticed that it was just closed. Did his implementation not work?

works just fine in my fork.

remram44 commented 2 years ago

Multiline strings were added #10, but not arrays. I don't remember why. I will try to look into it.

GTcreyon commented 2 years ago

Is there any progress on this? A feature like this is pretty much vital for a project I'm working on (I think, at least) and without it I'll have to write a separate script myself because I lack the knowledge to extend the plugin :P

h0lley commented 2 years ago

@GTcreyon the version I use probably differs too much at this point for another pull request, but it supports arrays of (multiline) strings, so there's no need for you to write your own.

GTcreyon commented 2 years ago

@h0lley Ah, lovely! Would you be able to explain briefly how to access it? I installed the original plugin through pip, and I have a limited knowledge of how that works, so a full explanation would be very helpful.

h0lley commented 2 years ago

@GTcreyon you can list the forks of this repository here: https://github.com/remram44/pybabel-godot/network/members click mine and read the readme.

on my system the babel_godot.py is located in /home/username/.local/lib/python3.9/site-packages. if you are on Windows just google where python packages are stored.

remram44 commented 2 years ago

You can simply install it with pip: pip install git+https://github.com/h0lley/pybabel-godot.git#egg=babel-godot

GTcreyon commented 2 years ago

Fantastic, thank you both! Have a great day!

GTcreyon commented 2 years ago

Ah, it seems to break when the string contains square brackets.

h0lley commented 2 years ago

@GTcreyon have you tried the implementation remram44 just merged?

otherwise, if you are using my fork, it would make more sense for you to create an issue about it in the corresponding repo.

but definitely try the original author's fix first.

GTcreyon commented 2 years ago

Apologies, yes, that solved it. I'll post the issue in the relevant repo. Thank you!