minetest / contentdb

A content database for Minetest mods, games, and more
https://content.minetest.net
GNU Affero General Public License v3.0
93 stars 45 forks source link

Tag description turns into Gettext metadata if empty #541

Closed Wuzzy2 closed 3 weeks ago

Wuzzy2 commented 3 weeks ago

Summary

If you hover a tag to get the tooltip or look at the description in the tag list in the package edit menu, for some tags, the description is the string for Gettext metadata.

It looks like this:

"Essen/Trinken: Project-Id-Version: PROJECT VERSION ..." and the string just goes on and on and on with lots of garbage.

Steps to reproduce
  1. Switch to Non-English language.
  2. Edit a package
  3. Look at the tag description for "Food / Drinks"
  4. Look at other tags

Alternative:

  1. Switch to Non-English language.
  2. Go to Games
  3. Hover the tags to get the tooltip for "Food / Drinks"
  4. Do the same for other tags

The result should be the same

Solution?

I'm pretty sure I know what is happening here without looking at the code.

I assume the offending tags have an empty description and ContentDB probably put them through a gettext call.

In Gettext, translating the empty string returns the metadata of the translation file, hence the garbage string with "Project-Id-Version", etc.

So the solution is that in the case of an empty string, do NOT pass it into gettext. Just return the empty string.

Wuzzy2 commented 3 weeks ago

Are you sure this fixed it? The empty string is falsy in Python so the "if" statement in above commit might always think the condition is True.

rubenwardy commented 3 weeks ago

image

In Python, a if condition else b is the same as condition ? a : b in C++/JS

Also, I did test this

Wuzzy2 commented 3 weeks ago

Sorry, I had a brainfart. Since the empty string is falsly, it must work, actually. It's OK.