zoukankan      html  css  js  c++  java
  • django-filer中文汉化无效的解决方案

    最近在django项目中使用django-filer管理后台文件,就算我把django的setting中额语言设置成为了LANGUAGE_CODE = 'zh-Hans',页面仍然汉化无效。我在django-filer的依赖安装目录页发现了zh-Hans的翻译包。

    根据博客https://stackoverflow.com/questions/12101811/trans-string-not-working-on-templates-but-trans-variable-does/12223367我找到了django拉取翻译包的代码。

    def to_locale(language):
        """Turn a language name (en-us) into a locale name (en_US)."""
        language, _, country = language.lower().partition('-')
        if not country:
            return language
        # A language with > 2 characters after the dash only has its first
        # character after the dash capitalized; e.g. sr-latn becomes sr_Latn.
        # A language with 2 characters after the dash has both characters
        # capitalized; e.g. en-us becomes en_US.
        country, _, tail = country.partition('-')
        country = country.title() if len(country) > 2 else country.upper()
        if tail:
            country += '-' + tail
        return language + '_' + country
    

      实际上,LANGUAGE_CODE = 'zh-Hans',拉取的是zh_Hans包里面的翻译内容,但是django-filer的翻译包的中文目录名称是zh-Hans,修改名称后果然解决问题

  • 相关阅读:
    Nacos安装部署文档
    mysql安装部署文档
    Postgresql数据库安装部署文档
    Sentinel安装部署文档
    Nginx安装部署手册
    golang 7. defer
    golang 6. 指针 *
    golang 5. import
    golang 4. 函数 func
    golang 3. 常量 const iota
  • 原文地址:https://www.cnblogs.com/dongqiSilent/p/10848106.html
Copyright © 2011-2022 走看看