Skip to content

tr will ignore "string" prefixes if it finds a match inside a str(). #80501

Open
@TheFoxKnocks

Description

@TheFoxKnocks

Godot version

v4.1.stable.official [9704596]

System information

Godot v4.1.stable - Windows 10.0.19045 - Vulkan (Compatibility) - NVIDIA GeForce RTX 3080 (NVIDIA; 31.0.15.3179) - 12th Gen Intel(R) Core(TM) i9-12900KF (24 Threads)

Issue description

I'm using Resources, and inside these Resources are 3 tags. Within my localization .CSV, all items which could be used as a tag are prefixed with "tag_", so, for example... "tag_area" is a key which translates into "AREA".

So, if I put the tag holding "area" into a variable, such as "tag3":

tr("tag_" + str(tag3))

What will happen is that it will decide to not grab "tag_area", but instead just grab "area".

All of my other tags work fine with this system, stuff like "tag_fire" or "tag_directional", but that's because there isn't a non-tag version. There is only "tag_fire" and "fire" does not exist. But I DO have "tag_area" and "area". It's pulling the wrong one.

Steps to reproduce

Create resource that has a variable holding a string.

Create a .CSV Localization file with a key that includes text from within that string.

Print it in code doing something like tr("key_first_half_" + str(key_second_half))" and it will print the result of key_second_half if that also exists as a key, ignoring the key_first_half_ prefix.

i.e; if you have 2 keys, and one is called "key_first_half_test" and the key_second_half variable is holding a string called "test", if your other key is just called "test" it'll mistakenly grab that and pretend the "key_first_half_" part doesn't exist.

Minimal reproduction project

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions