Add gettext context to tags and warnings, update translations

This commit is contained in:
rubenwardy 2024-06-09 13:48:00 +01:00
parent 36644216b2
commit 8b6bd8d282
42 changed files with 36546 additions and 10680 deletions

@ -1,126 +1,248 @@
# THIS FILE IS AUTOGENERATED: utils/extract_translations.py # THIS FILE IS AUTOGENERATED: utils/extract_translations.py
from flask_babel import gettext from flask_babel import pgettext
gettext("Jam / Game 2023") # NOTE: tags: title for jam_game_2023
gettext("Entries to the 2023 Minetest Game Jam ") pgettext("tags", "Jam / Game 2023")
gettext("Server Moderation and Tools") # NOTE: tags: description for jam_game_2023
gettext("Helps with server maintenance and moderation") pgettext("tags", "Entries to the 2023 Minetest Game Jam ")
gettext("Player vs Player (PvP)") # NOTE: tags: title for server_tools
gettext("Designed to be played competitively against other players") pgettext("tags", "Server Moderation and Tools")
gettext("Player Effects / Power Ups") # NOTE: tags: description for server_tools
gettext("For content that changes player effects, including physics, for example: speed, jump height or gravity.") pgettext("tags", "Helps with server maintenance and moderation")
gettext("Joke") # NOTE: tags: title for pvp
gettext("For humorous content, meant as a novelty or joke, not to be taken seriously, and that is not meant to be used seriously or long-term.") pgettext("tags", "Player vs Player (PvP)")
gettext("Shooter") # NOTE: tags: description for pvp
gettext("First person shooters (FPS) and more") pgettext("tags", "Designed to be played competitively against other players")
gettext("Mapgen / Biomes / Decoration") # NOTE: tags: title for player_effects
gettext("New mapgen or changes mapgen") pgettext("tags", "Player Effects / Power Ups")
gettext("Singleplayer-focused") # NOTE: tags: description for player_effects
gettext("Content that can be played alone") pgettext("tags", "For content that changes player effects, including physics, for example: speed, jump height or gravity.")
gettext("World Maintenance and Tools") # NOTE: tags: title for world_tools
gettext("Tools to manage the world") pgettext("tags", "World Maintenance and Tools")
gettext("Developer Tools") # NOTE: tags: description for world_tools
gettext("Tools for game and mod developers") pgettext("tags", "Tools to manage the world")
gettext("Adventure / RPG") # NOTE: tags: title for april_fools
gettext("Crafting") pgettext("tags", "Joke")
gettext("Big changes to crafting gameplay") # NOTE: tags: description for april_fools
gettext("Sounds / Music") pgettext("tags", "For humorous content, meant as a novelty or joke, not to be taken seriously, and that is not meant to be used seriously or long-term.")
gettext("Focuses on or adds new sounds or musical things") # NOTE: tags: title for shooter
gettext("Inventory") pgettext("tags", "Shooter")
gettext("Changes the inventory GUI") # NOTE: tags: description for shooter
gettext("Chat / Commands") pgettext("tags", "First person shooters (FPS) and more")
gettext("Focus on player chat/communication or who's primary function is interacting with the console.") # NOTE: tags: title for adventure__rpg
gettext("Plants and Farming") pgettext("tags", "Adventure / RPG")
gettext("Adds new plants or other farmable resources.") # NOTE: tags: title for mapgen
gettext("Complex installation") pgettext("tags", "Mapgen / Biomes / Decoration")
gettext("Requires futher installation steps, such as installing luarocks or editing the trusted mod setting") # NOTE: tags: description for mapgen
gettext("Multiplayer-focused") pgettext("tags", "New mapgen or changes mapgen")
gettext("Can/should only be used in multiplayer") # NOTE: tags: title for singleplayer
gettext("Tools / Weapons / Armor") pgettext("tags", "Singleplayer-focused")
gettext("Adds or changes tools, weapons, and armor") # NOTE: tags: description for singleplayer
gettext("Sims") pgettext("tags", "Content that can be played alone")
gettext("Mods and games that aim to simulate real life activity. Similar to SimCity/TheSims/OpenTTD/etc") # NOTE: tags: title for developer_tools
gettext("<16px") pgettext("tags", "Developer Tools")
gettext("Less than 16px") # NOTE: tags: description for developer_tools
gettext("Environment / Weather") pgettext("tags", "Tools for game and mod developers")
gettext("Improves the world, adding weather, ambient sounds, or other environment mechanics") # NOTE: tags: title for crafting
gettext("Mobs / Animals / NPCs") pgettext("tags", "Crafting")
gettext("Adds mobs, animals, and NPCs") # NOTE: tags: description for crafting
gettext("Puzzle") pgettext("tags", "Big changes to crafting gameplay")
gettext("Focus on puzzle solving instead of combat") # NOTE: tags: title for sound_music
gettext("Building") pgettext("tags", "Sounds / Music")
gettext("Focuses on building, such as adding new materials or nodes") # NOTE: tags: description for sound_music
gettext("Building Mechanics and Tools") pgettext("tags", "Focuses on or adds new sounds or musical things")
gettext("Adds game mechanics or tools that change how players build.") # NOTE: tags: title for inventory
gettext("Decorative") pgettext("tags", "Inventory")
gettext("Adds nodes with no other purpose than for use in building") # NOTE: tags: description for inventory
gettext("Magic / Enchanting") pgettext("tags", "Changes the inventory GUI")
gettext("One-of-a-kind / Original") # NOTE: tags: title for chat
gettext("For games and such that are of their own kind, distinct and original in nature to others of the same category.") pgettext("tags", "Chat / Commands")
gettext("16px") # NOTE: tags: description for chat
gettext("For 16px texture packs") pgettext("tags", "Focus on player chat/communication or who's primary function is interacting with the console.")
gettext("Custom mapgen") # NOTE: tags: title for plants_and_farming
gettext("Contains a completely custom mapgen implemented in Lua, usually requires worlds to be set to the 'singlenode' mapgen.") pgettext("tags", "Plants and Farming")
gettext("HUD") # NOTE: tags: description for plants_and_farming
gettext("For mods that grant the player extra information in the HUD") pgettext("tags", "Adds new plants or other farmable resources.")
gettext("API / Library") # NOTE: tags: title for complex_installation
gettext("Primarily adds an API for other mods to use") pgettext("tags", "Complex installation")
gettext("Mini-game") # NOTE: tags: description for complex_installation
gettext("Adds a mini-game to be played within Minetest") pgettext("tags", "Requires futher installation steps, such as installing luarocks or editing the trusted mod setting")
gettext("Education") # NOTE: tags: title for multiplayer
gettext("Either has educational value, or is a tool to help teachers ") pgettext("tags", "Multiplayer-focused")
gettext("Sports") # NOTE: tags: description for multiplayer
gettext("Storage") pgettext("tags", "Can/should only be used in multiplayer")
gettext("Adds or improves item storage mechanics") # NOTE: tags: title for tools
gettext("Survival") pgettext("tags", "Tools / Weapons / Armor")
gettext("Written specifically for survival gameplay with a focus on game-balance, difficulty level, or resources available through crafting, mining, ...") # NOTE: tags: description for tools
gettext("Player vs Environment (PvE)") pgettext("tags", "Adds or changes tools, weapons, and armor")
gettext("For content designed for one or more players that focus on combat against the world, mobs, or NPCs.") # NOTE: tags: title for simulation
gettext("GUI") pgettext("tags", "Sims")
gettext("For content whose main utility / feature is in GUI/formspec form") # NOTE: tags: description for simulation
gettext("64px") pgettext("tags", "Mods and games that aim to simulate real life activity. Similar to SimCity/TheSims/OpenTTD/etc")
gettext("For 64px texture packs") # NOTE: tags: title for magic
gettext("Commerce / Economy") pgettext("tags", "Magic / Enchanting")
gettext("Related to economies, money, and trading") # NOTE: tags: title for less_than_px
gettext("Minetest Game improved") pgettext("tags", "<16px")
gettext("Forks of MTG") # NOTE: tags: description for less_than_px
gettext("Jam / Weekly Challenges 2021") pgettext("tags", "Less than 16px")
gettext("For mods created for the Discord \"Weekly Challenges\" modding event in 2021") # NOTE: tags: title for building_mechanics
gettext("Transport") pgettext("tags", "Building Mechanics and Tools")
gettext("Adds or changes transportation methods. Includes teleportation, vehicles, ridable mobs, transport infrastructure and thematic content") # NOTE: tags: description for building_mechanics
gettext("Food / Drinks") pgettext("tags", "Adds game mechanics or tools that change how players build.")
gettext("Machines / Electronics") # NOTE: tags: title for environment
gettext("Adds machines useful in automation, tubes, or power.") pgettext("tags", "Environment / Weather")
gettext("Creative") # NOTE: tags: description for environment
gettext("Written specifically or exclusively for use in creative mode. Adds content only available through a creative inventory, or provides tools that facilitate ingame creation and doesn't add difficulty or scarcity") pgettext("tags", "Improves the world, adding weather, ambient sounds, or other environment mechanics")
gettext("Seasonal") # NOTE: tags: title for mobs
gettext("For content generally themed around a certain season or holiday") pgettext("tags", "Mobs / Animals / NPCs")
gettext("32px") # NOTE: tags: description for mobs
gettext("For 32px texture packs") pgettext("tags", "Adds mobs, animals, and NPCs")
gettext("Jam / Combat 2020") # NOTE: tags: title for puzzle
gettext("For mods created for the Discord \"Combat\" modding event in 2020") pgettext("tags", "Puzzle")
gettext("Jam / Game 2021") # NOTE: tags: description for puzzle
gettext("Entries to the 2021 Minetest Game Jam") pgettext("tags", "Focus on puzzle solving instead of combat")
gettext("128px+") # NOTE: tags: title for building
gettext("For 128px or higher texture packs") pgettext("tags", "Building")
gettext("Player customization / Skins") # NOTE: tags: description for building
gettext("Allows the player to customize their character by changing the texture or adding accessories.") pgettext("tags", "Focuses on building, such as adding new materials or nodes")
gettext("Strategy / RTS") # NOTE: tags: title for decorative
gettext("Games and mods with a heavy strategy component, whether real-time or turn-based") pgettext("tags", "Decorative")
gettext(" Jam / Game 2022") # NOTE: tags: description for decorative
gettext("Entries to the 2022 Minetest Game Jam ") pgettext("tags", "Adds nodes with no other purpose than for use in building")
gettext("Gore") # NOTE: tags: title for oneofakind__original
gettext("Blood, etc") pgettext("tags", "One-of-a-kind / Original")
gettext("Gambling") # NOTE: tags: description for oneofakind__original
gettext("Games of chance, gambling games, etc") pgettext("tags", "For games and such that are of their own kind, distinct and original in nature to others of the same category.")
gettext("Drugs") # NOTE: tags: title for survival
gettext("Contains illegal drugs, such as marijuana") pgettext("tags", "Survival")
gettext("Violence") # NOTE: tags: description for survival
gettext("Non-cartoon violence. May be towards fantasy or human-like characters") pgettext("tags", "Written specifically for survival gameplay with a focus on game-balance, difficulty level, or resources available through crafting, mining, ...")
gettext("Fear / Horror") # NOTE: tags: title for hud
gettext("Shocking and scary content. May scare young children") pgettext("tags", "HUD")
gettext("Bad Language") # NOTE: tags: description for hud
gettext("Contains swearing") pgettext("tags", "For mods that grant the player extra information in the HUD")
gettext("Alcohol / Tobacco") # NOTE: tags: title for storage
gettext("Contains alcohol and/or tobacco") pgettext("tags", "Storage")
# NOTE: tags: description for storage
pgettext("tags", "Adds or improves item storage mechanics")
# NOTE: tags: title for 16px
pgettext("tags", "16px")
# NOTE: tags: description for 16px
pgettext("tags", "For 16px texture packs")
# NOTE: tags: title for custom_mapgen
pgettext("tags", "Custom mapgen")
# NOTE: tags: description for custom_mapgen
pgettext("tags", "Contains a completely custom mapgen implemented in Lua, usually requires worlds to be set to the 'singlenode' mapgen.")
# NOTE: tags: title for library
pgettext("tags", "API / Library")
# NOTE: tags: description for library
pgettext("tags", "Primarily adds an API for other mods to use")
# NOTE: tags: title for mini-game
pgettext("tags", "Mini-game")
# NOTE: tags: description for mini-game
pgettext("tags", "Adds a mini-game to be played within Minetest")
# NOTE: tags: title for education
pgettext("tags", "Education")
# NOTE: tags: description for education
pgettext("tags", "Either has educational value, or is a tool to help teachers ")
# NOTE: tags: title for sports
pgettext("tags", "Sports")
# NOTE: tags: title for pve
pgettext("tags", "Player vs Environment (PvE)")
# NOTE: tags: description for pve
pgettext("tags", "For content designed for one or more players that focus on combat against the world, mobs, or NPCs.")
# NOTE: tags: title for jam_combat_mod
pgettext("tags", "Jam / Combat 2020")
# NOTE: tags: description for jam_combat_mod
pgettext("tags", "For mods created for the Discord \"Combat\" modding event in 2020")
# NOTE: tags: title for creative
pgettext("tags", "Creative")
# NOTE: tags: description for creative
pgettext("tags", "Written specifically or exclusively for use in creative mode. Adds content only available through a creative inventory, or provides tools that facilitate ingame creation and doesn't add difficulty or scarcity")
# NOTE: tags: title for gui
pgettext("tags", "GUI")
# NOTE: tags: description for gui
pgettext("tags", "For content whose main utility / feature is in GUI/formspec form")
# NOTE: tags: title for 64px
pgettext("tags", "64px")
# NOTE: tags: description for 64px
pgettext("tags", "For 64px texture packs")
# NOTE: tags: title for commerce
pgettext("tags", "Commerce / Economy")
# NOTE: tags: description for commerce
pgettext("tags", "Related to economies, money, and trading")
# NOTE: tags: title for mtg
pgettext("tags", "Minetest Game improved")
# NOTE: tags: description for mtg
pgettext("tags", "Forks of MTG")
# NOTE: tags: title for jam_weekly_2021
pgettext("tags", "Jam / Weekly Challenges 2021")
# NOTE: tags: description for jam_weekly_2021
pgettext("tags", "For mods created for the Discord \"Weekly Challenges\" modding event in 2021")
# NOTE: tags: title for transport
pgettext("tags", "Transport")
# NOTE: tags: description for transport
pgettext("tags", "Adds or changes transportation methods. Includes teleportation, vehicles, ridable mobs, transport infrastructure and thematic content")
# NOTE: tags: title for food
pgettext("tags", "Food / Drinks")
# NOTE: tags: title for technology
pgettext("tags", "Machines / Electronics")
# NOTE: tags: description for technology
pgettext("tags", "Adds machines useful in automation, tubes, or power.")
# NOTE: tags: title for seasonal
pgettext("tags", "Seasonal")
# NOTE: tags: description for seasonal
pgettext("tags", "For content generally themed around a certain season or holiday")
# NOTE: tags: title for 32px
pgettext("tags", "32px")
# NOTE: tags: description for 32px
pgettext("tags", "For 32px texture packs")
# NOTE: tags: title for jam_game_2021
pgettext("tags", "Jam / Game 2021")
# NOTE: tags: description for jam_game_2021
pgettext("tags", "Entries to the 2021 Minetest Game Jam")
# NOTE: tags: title for 128px
pgettext("tags", "128px+")
# NOTE: tags: description for 128px
pgettext("tags", "For 128px or higher texture packs")
# NOTE: tags: title for skins
pgettext("tags", "Player customization / Skins")
# NOTE: tags: description for skins
pgettext("tags", "Allows the player to customize their character by changing the texture or adding accessories.")
# NOTE: tags: title for strategy_rts
pgettext("tags", "Strategy / RTS")
# NOTE: tags: description for strategy_rts
pgettext("tags", "Games and mods with a heavy strategy component, whether real-time or turn-based")
# NOTE: tags: title for jam_game_2022
pgettext("tags", " Jam / Game 2022")
# NOTE: tags: description for jam_game_2022
pgettext("tags", "Entries to the 2022 Minetest Game Jam ")
# NOTE: content_warnings: title for gore
pgettext("content_warnings", "Gore")
# NOTE: content_warnings: description for gore
pgettext("content_warnings", "Blood, etc")
# NOTE: content_warnings: title for gambling
pgettext("content_warnings", "Gambling")
# NOTE: content_warnings: description for gambling
pgettext("content_warnings", "Games of chance, gambling games, etc")
# NOTE: content_warnings: title for violence
pgettext("content_warnings", "Violence")
# NOTE: content_warnings: description for violence
pgettext("content_warnings", "Non-cartoon violence. May be towards fantasy or human-like characters")
# NOTE: content_warnings: title for horror
pgettext("content_warnings", "Fear / Horror")
# NOTE: content_warnings: description for horror
pgettext("content_warnings", "Shocking and scary content. May scare young children")
# NOTE: content_warnings: title for bad_language
pgettext("content_warnings", "Bad Language")
# NOTE: content_warnings: description for bad_language
pgettext("content_warnings", "Contains swearing")
# NOTE: content_warnings: title for alcohol_tobacco
pgettext("content_warnings", "Alcohol / Tobacco")
# NOTE: content_warnings: description for alcohol_tobacco
pgettext("content_warnings", "Contains alcohol and/or tobacco")
# NOTE: content_warnings: title for drugs
pgettext("content_warnings", "Drugs")
# NOTE: content_warnings: description for drugs
pgettext("content_warnings", "Contains recreational drugs other than alcohol or tobacco")

@ -21,7 +21,7 @@ import os
import typing import typing
from flask import url_for from flask import url_for
from flask_babel import lazy_gettext, get_locale, gettext from flask_babel import lazy_gettext, get_locale, gettext, pgettext
from flask_sqlalchemy.query import Query from flask_sqlalchemy.query import Query
from sqlalchemy import or_, func from sqlalchemy import or_, func
from sqlalchemy.dialects.postgresql import insert from sqlalchemy.dialects.postgresql import insert
@ -987,8 +987,8 @@ class ContentWarning(db.Model):
def get_translated(self): def get_translated(self):
# Translations are automated on dynamic data using `extract_translations.py` # Translations are automated on dynamic data using `extract_translations.py`
return { return {
"title": gettext(self.title), "title": pgettext("tags", self.title),
"description": gettext(self.description), "description": pgettext("content_warnings", self.description),
} }
def as_dict(self): def as_dict(self):
@ -1019,8 +1019,8 @@ class Tag(db.Model):
def get_translated(self): def get_translated(self):
# Translations are automated on dynamic data using `extract_translations.py` # Translations are automated on dynamic data using `extract_translations.py`
return { return {
"title": gettext(self.title), "title": pgettext("tags", self.title),
"description": gettext(self.description) if self.description else "", "description": pgettext("tags", self.description) if self.description else "",
} }
def as_dict(self): def as_dict(self):

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -10,7 +10,7 @@ base_url = "https://content.minetest.net"
translations = [] translations = []
def add_translations_from_api_array(path: str, fields: List[str]): def add_translations_from_api_array(context: str, path: str, fields: List[str]):
print(f"Extracting translations from {path}") print(f"Extracting translations from {path}")
url = base_url + path url = base_url + path
req = requests.get(url) req = requests.get(url)
@ -18,20 +18,23 @@ def add_translations_from_api_array(path: str, fields: List[str]):
for i, row in enumerate(json): for i, row in enumerate(json):
for field in fields: for field in fields:
if row.get(field) is not None: if row.get(field) is not None:
translations.append(row[field]) hint = f"{context}: {field} for {row['name']}"
translations.append((context, hint, row[field]))
add_translations_from_api_array("/api/tags/", ["title", "description"]) add_translations_from_api_array("tags", "/api/tags/", ["title", "description"])
add_translations_from_api_array("/api/content_warnings/", ["title", "description"]) add_translations_from_api_array("content_warnings", "/api/content_warnings/", ["title", "description"])
with open("app/_translations.py", "w") as f: with open("app/_translations.py", "w") as f:
f.write("# THIS FILE IS AUTOGENERATED: utils/extract_translations.py\n\n") f.write("# THIS FILE IS AUTOGENERATED: utils/extract_translations.py\n\n")
f.write("from flask_babel import gettext\n\n") f.write("from flask_babel import gettext\n\n")
for translation in translations: for (context, hint, translation) in translations:
escaped = translation.replace('\n', '\\n').replace("\"", "\\\"") escaped = translation.replace('\n', '\\n').replace("\"", "\\\"")
f.write(f"gettext(\"{escaped}\")\n") if hint:
f.write(f"# NOTE: {hint}\n")
f.write(f"pgettext(\"{context}\", \"{escaped}\")\n")
subprocess.run(["pybabel", "extract", "-F", "babel.cfg", "-k", "lazy_gettext", "-o", "translations/messages.pot", "."]) subprocess.run(["pybabel", "extract", "-F", "babel.cfg", "-k", "lazy_gettext", "-o", "translations/messages.pot", "-c", "NOTE", "."])
subprocess.run(["pybabel", "update", "-i", "translations/messages.pot", "-d", "translations", "--no-fuzzy-matching"]) subprocess.run(["pybabel", "update", "-i", "translations/messages.pot", "-d", "translations", "--no-fuzzy-matching"])