Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert language code to locale name?

Tags:

django

locale

How to convert language code to locale name in Django?

For example:

  • zh-cn to zh_CN
  • zh-Hans to zh_Hans
like image 823
Rockallite Avatar asked Oct 27 '25 03:10

Rockallite


1 Answers

from django.utils.translation import to_locale
from django.conf import settings

print to_locale(settings.LANGUAGE_CODE)
like image 97
Rockallite Avatar answered Oct 30 '25 17:10

Rockallite