简体   繁体   English

不区分大小写的翻译

[英]Case Insensitive Translation

I'm displaying certain strings in my app in some places as regular case and in some places as upper case:我在我的应用程序中显示某些字符串在某些地方作为常规大小写,在某些地方作为大写:

{% trans item.name %}
{% trans item.name.upper %}

I'm specifying translations using the .po/.mo files:我正在使用 .po/.mo 文件指定翻译:

msgid "Welcome"  
msgstr "歓迎"

And the translation seems to be case-sensitive.并且翻译似乎区分大小写。 'Welcome' gets translated to '歓迎' but 'WELCOME' does not get translated. “欢迎”被翻译成“歓迎”,但“欢迎”没有被翻译。 Is there an easy way to get it to translate case insensitive?有没有一种简单的方法可以让它翻译不区分大小写? It seems like it would be cleaner than providing each of these translations twice.似乎比提供这些翻译中的每一个两次更干净。

The only "easy" way to do it is to always use either uppercase or lowercase strings and translate those.唯一“简单”的方法是始终使用大写或小写字符串并翻译它们。 But as far as I know there is no support from either Django or Gettext for case insensitivity.但据我所知,Django 或 Gettext 都不支持不区分大小写。

The question you should ask yourself is... is it really correct?你应该问自己的问题是……它真的正确吗? I mean, in some languages the meaning of a word can change with casing.我的意思是,在某些语言中,单词的含义会随着大小写而变化。 So I wonder if adding the capitalized translations automatically might be a better solution.所以我想知道是否自动添加大写翻译可能是一个更好的解决方案。 That way you can atleast change them if it's needed for a specific language.这样,如果特定语言需要,您至少可以更改它们。

One way to do display in case what you want is using CSS.如果您想要什么,则一种显示方式是使用 CSS。 Example:例子:

<style>
   p.uppercase {text-transform: uppercase;}
   p.lowercase {text-transform: lowercase;}
   p.capitalize {text-transform: capitalize;}
</style>

In page Django, use:在页面 Django 中,使用:

<p class="uppercase">{% trans 'Welcome' %}</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM