Django应用程序的通用代词处理
项目描述
代词很难处理。考虑到用户的偏好转写信件或副本更加困难。想要打破性别二元论几乎是不可能的 - 直到现在。《django-pronouns》来了!
当用户注册时,他们可以选择他们偏好的代词(通常伪装成性别选项)。有常用代词(他/她),以及更中性的代词(他们、它、xir等)。在你的副本中使用它们就像确定需要哪种形式一样简单,而《django-pronouns》会做剩下的工作。观察:
>>> "{{ user.pronoun.subject|title }} is awesome."
"She is awesome."
>>> "It is {{ user.name|pluralize }} birthday today. Go wish {{ user.pronoun.object }} a happy birthday!"
"It is Tims birthday today. Go wish him happy birthday!"
>>> "{{ user.name }} looked at {{ user.pronoun.reflexive }} in the mirror."
"Alex looked at himself in the mirror."
>>> "{{ user.pronoun.possessive_determiner|title }} stuff is on the table."
"Her stuff is on the table."
>>> "This guitar is {{ user.pronoun.possessive_pronoun }}."
"This guitar is hers."
如果确定哪种形式太烦人,我们也能提供帮助。五种形式中的每一种都有一个别名,由阳性和阴性形式加下划线组成,以及(新)Spivak形式
主语: he_she,shen_he,ey
宾语: him_her,her_him,em
反身代词: himself_herself,herself_himself,emself
所有格限定词: his_her,her_his,eir
所有格代词: his_hers,hers_his,eirs
女性和男性代词合并,因为它们单独使用时可能会引起歧义。《his》可能指代所有格限定词,也可能指代所有格代词,而《her》可能指代所有格限定词或宾格形式。选择Spivak是因为它是唯一一个在五种形式中都不含糊的形式。
安装
通过pip安装
$ pip install django-pronouns
将其添加到Django的< span class="docutils literal">INSTALLED_APPS
INSTALLED_APPS = (
# ...
"django_pronouns",
# ...
)
最后,如果您想的话,可以添加默认的代词集
$ python manage.py loaddata pronouns
您可以通过管理区域稍后编辑这些代词,添加更多或删除一些。
使用
只需将一个< span class="docutils literal">ForeignKey链接添加到代词模型,即可将代词添加到任何模型。当与UserProfile结合使用时,代词工作得非常好。
from django.db import models
from django.contrib.auth.models import User
from django_pronouns.models import Pronoun
class UserProfile(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=255)
dob = models.DateField()
pronoun = models.ForeignKey(Pronoun)
像使用任何其他ForeignKey一样在表单中使用它们。
在您的模板中,您可以请求任何代词形式
{{ user.pronoun.subject|title }} is awesome.
It is {{ user.name|pluralize }} birthday today. Go wish {{ user.pronoun.object }} happy birthday!
{{ user.name }} looked at {{ user.pronoun.reflexive }} in the mirror.
{{ user.pronoun.possessive_determiner|title }} stuff is on the table.
This guitar is {{ user.pronoun.possessive_pronoun }}.
还提供了一些快捷方式,因为确定使用哪种形式可能会很烦人。五种形式中的每一种都有一个由性别形式和下划线连接的别名,以及Spivak形式。
主语: he_she,she_he,ey
宾语: him_her,her_him,em
反身代词: himself_herself,herself_himself,emself
所有格限定词: his_her,her_his,eir
所有格代词: his_hers,hers_his,eirs
使用方法与使用名称形式相同
{{ user.pronoun.she_he|title }} is awesome.
It is {{ user.name|pluralize }} birthday today. Go wish {{ user.pronoun.him_her }} a happy birthday!
{{ user.name }} looked at {{ user.pronoun.emself }} in the mirror.
{{ user.pronoun.his_her|title }} stuff is on the table.
This guitar is {{ user.pronoun.hers_his }}.
项目详情
django-pronouns-0.3.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | afdb0dd7cda80ac7ba3fec53cf472f97242f5692620036cc04f4ae8e14ed47d4 |
|
MD5 | 4ad443d6f15715a39d43751e2fb1c0c4 |
|
BLAKE2b-256 | c1b4b425f6db18cd088e7b3a8caa8c2fe556067a20b8e982d3246dac603b33cb |