Skip to main content
 首页 » 编程设计

Python gettext Genitiv 的

2025年05月04日12jpfss

我想将文本翻译成德语,但我对属格 's 有疑问。在德语中,除了单词以 s 结尾(“James's car”->“James'汽车”)。 所以,如果我有以下内容:

_("%(name)'s car is nice") % name 

“John”和“James”的结果是:

John's car is nice      -> Correct 
Johns Auto ist schön    -> Correct (ist means is and schön means nice or beautiful). 
James's car is nice     -> Correct 
Jamess Auto is schön    -> Wrong it has to be James' 

由于我是程序的开发者,我还可以更新源代码并添加新功能。

请您参考如下方法:

写一个函数来生成genitiv:

def genitiv(name): 
    if name[-1]=='s': 
       return _(u"%s'" % name) 
    else: 
       return _(u"%s's" % name)