Add ability to translate tags and content warnings

This commit is contained in:
rubenwardy
2024-06-07 05:28:57 +01:00
parent 7d00a5b969
commit d2c5779301
10 changed files with 73 additions and 21 deletions

View File

@@ -906,6 +906,13 @@ class ContentWarning(db.Model):
regex = re.compile("[^a-z_]")
self.name = regex.sub("", self.title.lower().replace(" ", "_"))
def get_translated(self):
# Translations are automated on dynamic data using `extract_translations.py`
return {
"title": gettext(self.title),
"description": gettext(self.description),
}
def as_dict(self):
description = self.description if self.description != "" else None
return { "name": self.name, "title": self.title, "description": description }
@@ -931,6 +938,13 @@ class Tag(db.Model):
regex = re.compile("[^a-z_]")
self.name = regex.sub("", self.title.lower().replace(" ", "_"))
def get_translated(self):
# Translations are automated on dynamic data using `extract_translations.py`
return {
"title": gettext(self.title),
"description": gettext(self.description),
}
def as_dict(self):
description = self.description if self.description != "" else None
return {