简体   繁体   中英

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:

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.

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. Example:

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

In page Django, use:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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