I used a lot of {% trans "" %} tags in my Django templates. I am wondering how does Django perform the string replacement on server-side in real-time from the mo file. Does it have a big impact on performance compared with templates without localized strings?

And if it does effect performance, can I compile the templates beforehand (generating templates with the translated strings filled in)?

有帮助吗?

解决方案

I don't see anything about this in the docs.

If you are concerned about the speed impact of translations on your site, it's best to measure it.

  1. Disable translations by setting USE_I18N = False in your settings.py
  2. Stress test your site, for example with ab (the Apache benchmarking tool), or other
  3. Turn translations back on and repeat the stress test

That said, I don't for sure know how Django handles the {% trans "" %} tags when USE_I18N = False. To be extra paranoid, maybe you can delete all these tags and measure again. I think the results of your benchmark tests would be interesting for everyone.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top