Skip to content

Commit

Permalink
i18n prural_items
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed May 21, 2024
1 parent 2bdfb06 commit 74cdd1e
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 26 deletions.
4 changes: 3 additions & 1 deletion journal/templates/collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ <h3>
</p>
<p>
{% for cat, count in collection.get_summary.items %}
{% if count %}<span>{{ count }} {{ cat|prural_items }}</span>&nbsp;&nbsp;{% endif %}
{% if count %}
<span>{% prural_items count cat %}</span>&nbsp;&nbsp;
{% endif %}
{% endfor %}
</p>
{% if featured_since %}
Expand Down
61 changes: 40 additions & 21 deletions journal/templatetags/collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.translation import ngettext

from journal.models import Collection
from journal.models.mixins import UserOwnedObjectMixin
Expand Down Expand Up @@ -27,24 +28,42 @@ def user_stats_of(collection: Collection, identity: APIdentity):
return collection.get_stats(identity) if identity else {}


@register.filter(is_safe=True)
@stringfilter
def prural_items(category: str):
# TODO support i18n here
# return _(f"items of {category}")
if category == "book":
return "本书"
elif category == "movie":
return "部电影"
elif category == "tv":
return "部剧集"
elif category == "album" or category == "music":
return "张专辑"
elif category == "game":
return "个游戏"
elif category == "podcast":
return "个播客"
elif category == "performance":
return "场演出"
else:
return category
@register.simple_tag()
def prural_items(count: int, category: str):
match category:
case "book":
return ngettext("%(count)d book", "%(count)d books", count,) % {
"count": count,
}
case "movie":
return ngettext("%(count)d movie", "%(count)d movies", count,) % {
"count": count,
}
case "tv":
return ngettext("%(count)d tv show", "%(count)d tv shows", count,) % {
"count": count,
}
case "music":
return ngettext("%(count)d album", "%(count)d albums", count,) % {
"count": count,
}
case "game":
return ngettext("%(count)d game", "%(count)d games", count,) % {
"count": count,
}
case "podcast":
return ngettext("%(count)d podcast", "%(count)d podcasts", count,) % {
"count": count,
}
case "performance":
return ngettext(
"%(count)d performance",
"%(count)d performances",
count,
) % {
"count": count,
}
case _:
return ngettext("%(count)d item", "%(count)d items", count,) % {
"count": count,
}
98 changes: 95 additions & 3 deletions locale/zh_Hans/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-20 11:52-0400\n"
"POT-Creation-Date: 2024-05-20 18:21-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -857,12 +857,12 @@ msgid "Are you sure to delete?"
msgstr "确认删除吗?"

#: catalog/templates/catalog_delete.html:47
#: catalog/templates/catalog_merge.html:91
#: catalog/templates/catalog_merge.html:91 neodb-takahe/activities/admin.py:25
msgid "Yes"
msgstr "是"

#: catalog/templates/catalog_delete.html:48
#: catalog/templates/catalog_merge.html:92
#: catalog/templates/catalog_merge.html:92 neodb-takahe/activities/admin.py:26
msgid "No"
msgstr "否"

Expand Down Expand Up @@ -2010,6 +2010,62 @@ msgstr ""
msgid "分享"
msgstr ""

#: journal/templatetags/collection.py:36
#, python-format
msgid "%(count)d book"
msgid_plural "%(count)d books"
msgstr[0] "%(count)d 本书"
msgstr[1] "%(count)d 本书"

#: journal/templatetags/collection.py:44
#, python-format
msgid "%(count)d movie"
msgid_plural "%(count)d movies"
msgstr[0] "%(count)d 部电影"
msgstr[1] "%(count)d 部电影"

#: journal/templatetags/collection.py:52
#, python-format
msgid "%(count)d tv show"
msgid_plural "%(count)d tv shows"
msgstr[0] "%(count)d 部电视剧"
msgstr[1] "%(count)d 部电视剧"

#: journal/templatetags/collection.py:60
#, python-format
msgid "%(count)d album"
msgid_plural "%(count)d albums"
msgstr[0] "%(count)d 张专辑"
msgstr[1] "%(count)d 张专辑"

#: journal/templatetags/collection.py:68
#, python-format
msgid "%(count)d game"
msgid_plural "%(count)d games"
msgstr[0] "%(count)d 个游戏"
msgstr[1] "%(count)d 个游戏"

#: journal/templatetags/collection.py:76
#, python-format
msgid "%(count)d podcast"
msgid_plural "%(count)d podcasts"
msgstr[0] "%(count)d 个播客"
msgstr[1] "%(count)d 个播客"

#: journal/templatetags/collection.py:84
#, python-format
msgid "%(count)d performance"
msgid_plural "%(count)d performances"
msgstr[0] "%(count)d 场演出"
msgstr[1] "%(count)d 场演出"

#: journal/templatetags/collection.py:92
#, python-format
msgid "%(count)d item"
msgid_plural "%(count)d items"
msgstr[0] "%(count)d 个条目"
msgstr[1] "%(count)d 个条目"

#: journal/views/collection.py:38
#, python-brace-format
msgid "Collection by {0}"
Expand Down Expand Up @@ -2148,6 +2204,42 @@ msgstr ""
msgid "target site domain name"
msgstr ""

#: neodb-takahe/activities/admin.py:18
msgid "Local Identity"
msgstr ""

#: neodb-takahe/core/admin.py:8
msgid "config options type"
msgstr ""

#: neodb-takahe/core/admin.py:13
msgid "System"
msgstr "系统"

#: neodb-takahe/core/admin.py:14
msgid "Identity"
msgstr "身份"

#: neodb-takahe/core/admin.py:15
msgid "User"
msgstr ""

#: neodb-takahe/users/admin.py:147
msgid "Local Source Identity"
msgstr ""

#: neodb-takahe/users/admin.py:153
msgid "Local Target Identity"
msgstr ""

#: neodb-takahe/users/views/auth.py:20
msgid "No account was found with that email and password."
msgstr ""

#: neodb-takahe/users/views/auth.py:21
msgid "This account is inactive."
msgstr ""

#: social/templates/activity/create_collection.html:17 takahe/utils.py:553
msgid "created collection"
msgstr "创建了收藏单"
Expand Down
2 changes: 1 addition & 1 deletion users/templates/users/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h4>{% trans "Welcome" %}</h4>
placeholder="email"
autocomplete="email" />
{% if request.user.pending_email %}
<small> {% blocktrans pending_email=request.user.pending_email %}Please click the confirmation link in the email sent to {{ pending_email }}; if you haven't received it for more than a few minutes, please input and save again.{% endblocktrans %} </small>
<small> {% blocktrans with pending_email=request.user.pending_email %}Please click the confirmation link in the email sent to {{ pending_email }}; if you haven't received it for more than a few minutes, please input and save again.{% endblocktrans %} </small>
{% endif %}
{% for error in form.email.errors %}<small>{{ error }}</small>{% endfor %}
</label>
Expand Down

0 comments on commit 74cdd1e

Please sign in to comment.