跳转到主要内容

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_sheshen_heey

  • 宾语him_herher_himem

  • 反身代词himself_herselfherself_himselfemself

  • 所有格限定词his_herher_hiseir

  • 所有格代词his_hershers_hiseirs

女性和男性代词合并,因为它们单独使用时可能会引起歧义。《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_sheshe_heey

  • 宾语him_herher_himem

  • 反身代词himself_herselfherself_himselfemself

  • 所有格限定词his_herher_hiseir

  • 所有格代词his_hershers_hiseirs

使用方法与使用名称形式相同

{{ 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 (3.7 kB 查看哈希值)

上传时间

由以下支持