开发者

django internationalizing images of the layout

开发者 https://www.devze.com 2023-03-17 17:47 出处:网络
am building a website that will be in multi language, I was wondering how would I implement different images from static folder based on language?

am building a website that will be in multi language, I was wondering how would I implement different images from static folder based on language?

for example, when visiting the main site the layout will load in english but when changed to french the logo and images attached to the 开发者_StackOverflow社区layout will change based on the requested language.

regards,


In the template, LANGUAGE_CODE might help you out, then you can provide alternate image paths or whatever to your correct images. Sorry that I don't know a more elegant way.

I got that information from the Django Book. The link shows where exactly I got it from.


I'm not sure, but what if try to take advantage of builtin i18n component.
So you have different folders for diff languages like:

  • Images
    • en_images_folder
      • logo.png
      • banner.png
    • fr_images_folder
    • ru_images_folder (folder names must be unique enough, so as not to interfere with normal translations)

And in template you access them as:

<img src={{STATIC_URL}}/images/fr_images_folder/logo.png>

Now change it to:

<img src={{STATIC_URL}}/images/{% trans "fr_images_folder" %}/logo.png>

Generate po files and, for example, in fr translation make it:

#: .\test_temp\test.html.py:5
msgid "en_images_folder"
msgstr "fr_images_folder"

PS: I didn't try it, but i think it should work @John Doe already provided link to docs so i won't repeat it.

0

精彩评论

暂无评论...
验证码 换一张
取 消