Django全球化工具

Django-G11N的Python项目详细描述


https://img.shields.io/codeship/550d9e60-1630-0134-9ad4-2e1718fe265e/default.svghttps://coveralls.io/repos/bitbucket/hellwig/django-g11n/badge.svg?branch=defaulthttps://img.shields.io/pypi/v/django-g11n.svghttps://img.shields.io/badge/Donate-PayPal-blue.svghttps://img.shields.io/badge/Donate-Patreon-orange.svg

Django全球化

这是什么?

  • 有助于国际化和本地化的django应用程序。

它解决了什么问题?

  • 猜猜请求的来源国。
  • 返回一个国家使用的货币。
  • 获取语言代码。
  • 不使用商业数据库,使用原始数据源。
  • IPv4和IPv6。
  • 模型布局合理。

如何安装?

$ pip install django-g11n

使用django-integrator来 将此应用程序集成到您的django实例,或者您可以通过 常用的手动方式。

我怎么用?

# To fill initial data use the command
$ python manage.py g11n_setup
# To guess someones IP
$ python manage.py guess_tld_by_ip 8.8.8.8
# To find out what the currency is most likely associated with an tld
$ python manage.py currency_by_tld gb
#

当然,您很可能希望通过请求实例使用它,因为 查看django_g11n.tools.by_request,它具有以下功能:

  • IP地址(请求)
  • 猜测国家(请求)
  • 猜测语言(请求)
  • 猜测货币(请求)
  • 猜测国家语言货币(请求)

将返回您可能从函数名猜到的数据。

但是,由于所有数据都在模型中,因此在 像这样的交互式shell会话:

In[1]:fromdjango_g11n.tools.fetchimportiprange_by_ipIn[2]:iprange=iprange_by_ip('194.60.62.36')In[3]:iprange.__dict__Out[3]:{'_state':<django.db.models.base.ModelStateat0x7f581dd9f9e8>,'broadcast_hex':'000000000000000000000000c23c3fff','dts_delete':None,'dts_insert':datetime.datetime(2016,10,10,10,19,55,241150,tzinfo=<UTC>),'dts_update':None,'id':58935,'identifier':'rigb4_0_24_c23c3fff_0_24_c23c0000','ipv':4,'network_hex':'000000000000000000000000c23c0000','reference_id':235,'regional_nic':'ripencc','tld':'GB'}In[4]:country=iprange.referenceIn[5]:country.__dict__Out[5]:{'_state':<django.db.models.base.ModelStateat0x7f581dd9fda0>,'code_2':'GB','code_3':'GBR','dts_delete':None,'dts_insert':datetime.datetime(2016,10,10,10,18,31,274177,tzinfo=<UTC>),'dts_update':None,'id':235,'iso3166':True,'numeric':826,'obsolete':False}In[6]:country.languagecountry_set.all()Out[6]:[<LanguageCountry:en-GB>]In[7]:language_country=country.languagecountry_set.all()[0]In[8]:language_country.language.__dict__Out[8]:{'_state':<django.db.models.base.ModelStateat0x7f581dd3cba8>,'bibliographic':'eng','code_a2':'en','dts_delete':None,'dts_insert':datetime.datetime(2016,10,10,10,20,1,110024,tzinfo=<UTC>),'dts_update':None,'english':'English','french':'anglais','id':123,'iso639_2':True,'obsolete':False,'terminologic':''}In[9]:country.countryname_set.all()Out[9]:[<CountryName:UnitedKingdom>,<CountryName:UnitedKingdomofGreatBritainandNorthernIreland>]In[10]:country.countryname_set.all()[1].__dict__Out[10]:{'_country_cache':<Country:GB>,'_state':<django.db.models.base.ModelStateat0x7f581dd43d30>,'country_id':235,'default':False,'dts_delete':None,'dts_insert':datetime.datetime(2016,10,10,10,18,31,337353,tzinfo=<UTC>),'dts_update':None,'id':248,'iso3166':True,'language_id':42,'value':'United Kingdom of Great Britain and Northern Ireland'}In[11]:country.currency_set.all()Out[11]:[<Currency:GBP826>]In[12]:country.currency_set.all()[0].__dict__Out[12]:{'_reference_cache':<Country:GB>,'_state':<django.db.models.base.ModelStateat0x7f581dd49940>,'code':'GBP','country':'UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND (THE)','decimals':2,'default':True,'dts_delete':None,'dts_insert':datetime.datetime(2016,10,10,10,18,31,670707,tzinfo=<UTC>),'dts_update':None,'id':754,'is_fund':False,'iso4217':True,'name':'Pound Sterling','numeric':826,'reference_id':235}In[13]:country.region_set.all()Out[13]:[<Region:826UnitedKingdomofGreatBritainandNorthernIreland>]In[14]:region=country.region_set.all()[0]In[15]:region.__dict__Out[15]:{'_reference_cache':<Country:GB>,'_state':<django.db.models.base.ModelStateat0x7f581dd4e4a8>,'dts_delete':None,'dts_insert':datetime.datetime(2016,10,10,10,20,1,369095,tzinfo=<UTC>),'dts_update':datetime.datetime(2016,10,10,10,20,5,295071,tzinfo=<UTC>),'english':'United Kingdom of Great Britain and Northern Ireland','id':116,'numeric':'826','obsolete':False,'reference_id':235,'unsd_m49':True}In[16]:defprint_regions(region):....:whileTrue:....:print(region.numeric,' - ',region.english)....:chains=region.chains_region_is_lower.all()....:ifchains.count()==0:....:break....:region=chains[0].upper....:In[17]:print_regions(region)826-UnitedKingdomofGreatBritainandNorthernIreland154-NorthernEurope150-Europe001-WorldIn[18]:

如上所示,大多数车型都是通过 “reference”字段,这是因为大多数表都是从外部填充的 来源。对于我们使用ISO的国家、语言和货币,对于我们使用的地区 UN-SD M49和IPrange可从区域NIC下载。 因为他们的国名代表性略有不同, 每个表中的国家名称在导入时和导入后都被保留 该制度试图找到与该国适当的外交关系 桌子。

这是什么执照?

双条款bsd

我怎样才能得到支持?

请使用repo的bug追踪器留下任何问题、反馈, 建议和意见。我会根据我的时间和外表来处理 很有趣。如果您需要担保支持,请通过 发电子邮件以便我们讨论适当的补偿。

签字

我的工作对你有帮助还是有价值?您可以通过以下方式来回报我:

https://paypal.me/MartinHellwig

Donate via PayPal.Me

-或-

https://www.patreon.com/hellwig

Donate via Patreon

谢谢你!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无法在Netbeans 8.2 JDK8u231中创建java Maven项目(Web应用程序)   java如何以设定的时间间隔生成随机数?   java从socket和inputStream的慢速读取   spring SCORM:Java中基于Web的SCORM播放器   Java将函数传递给方法   java绑定通用服务及其实现和子类型   java如何在运行时从选择列表框中动态选择选项?爪哇硒   java Selenium WebDriver什么是“Selenium客户端和WebDriver语言绑定”   elasticsearch需要elasticsearch高级Java客户端更新ByQueryRequest API帮助   JAVA哈希表查找最大值   WSDL操作中的java soapAction属性为空   java访问封闭类或父类方法的一般方法   eclipse在java中运行带有SeleneTestCase的ANT。lang.NoClassDefFoundError   java Hazelcast不会在节点启动时填充ReplicatedMap   如何在Java中从excel中读取特定行?   html JAVA将本地时间(GMT+8)转换为UTC时间   java将自定义端点添加到Spring数据REST存储库中,并以大摇大摆的方式显示   java计算未来位置