vue动态设置国际化_Dynaconf –让您的设置动态化

vue动态设置国际化

Dynaconf (Dynaconf)

dynaconf – The dynamic configurator for your Python Project

dynaconf – Python项目的dyna麦克风配置

MIT License
Coverage Status

麻省理工学院执照
承保范围

dynaconf is an OSM (Object Settings Mapper) it can read settings variables from a set of different data stores such as python settings files, environment variables, redis, memcached, ini files, json files, yaml files and you can customize dynaconf loaders to read from wherever you want. (maybe you really want to read from xml files ughh?)

dynaconfOSM(O bject 小号 ettings 中号冲击片雷管),它可以读取从一组不同的数据存储的设置变量,如巨蟒的设置文件环境变量 ,Redis的 ,memcached的 ,INI文件 ,JSON文件 ,YAML文件 ,你可以自定义dynaconf加载程序,可从任何位置读取。 (也许您真的想从xml文件中读取ughh?)

GITHUB REPO: https://github.com/rochacbruno/dynaconf

GITHUB REPO: https : //github.com/rochacbruno/dynaconf

什么是Dynaconf? (What is Dynaconf?)

Dynaconf is a common point of access to settings variables, you import only one object in your project and from that object you can access settings variables from Python settings file, from environment variables, from parsed yaml, ini, json or xml files, from datastores as Redis and MongoDB or from wherever your need if you write a simple dynaconf loader.

Dynaconf是访问设置变量的常见点,您只需在项目中导入一个对象,就可以从该对象访问Python设置文件,环境变量,解析的yaml,ini,json或xml文件,数据存储中的设置变量。作为Redis和MongoDB的源代码,或者编写简单的dynaconf加载器的源代码。

这个怎么运作 (How it works)

安装它 (Install it)

pip install dynaconf

pip install dynaconf

用它 (Use it)

from dynaconf import settings
print settings.SOME_VARIABLE
or
print settings.get('SOME_VARIABLE')
from dynaconf import settings
print settings.SOME_VARIABLE
or
print settings.get('SOME_VARIABLE')
 

By default Dynaconf will try to use a file called settings.py on the root of your project, if you place that file there all upper case variables will be read

默认情况下,Dynaconf将尝试在项目的根目录上使用一个名为settings.py的文件,如果将该文件放在此处,则将读取所有大写变量

You can also replace the file exporting an environment variable pointing to the module or location for the settings file.

您也可以替换导出环境变量的文件,该环境变量指向设置文件的模块或位置。

Doing that when you use from dynaconf import settings the variables will be read from that file.

from dynaconf import settings使用变量时,将从该文件中读取变量。

那么它是如何动态的呢? (So how it is Dynamic?)

Now think you have your program done and you want to deploy to a certain infrastructure for testing or maybe different deployment, you don’t need to rewrite the settings file. Just export some variables to your environment.

现在,您已经完成了程序,并且想要部署到某个基础结构以进行测试或进行其他部署,则无需重写设置文件。 只需将一些变量导出到您的环境即可。

export DYNACONF_MYSQL_HOST=myserver.com
export DYNACONF_MYSQL_HOST=myserver.com
 

Now in your project you can do:

现在在您的项目中,您可以执行以下操作:

The default prefix for exported envvars is by default DYNACONF_ but you also can change it if needed.

默认情况下,导出的envvars的默认前缀为DYNACONF_,但您也可以根据需要更改它。

但是,如果我要导出一些类型化的值怎么办? (But what if I have some typed values to export?)

You can also define type casting when exporting and those types will be used to parse the values.

您还可以在导出时定义类型转换,这些类型将用于解析值。

export DYNACONF_NUMBER='@int 123'
export DYNACONF_FLOAT='@float 12.2'
export DYNACONF_FLAG='@bool yes'
export DYNACONF_FLAG2='@bool disabled'
export DYNACONF_LIST='@json [1, 2, 3, 4]'
export DYNACONF_DICT='@json {"name": "Bruno"}'
export DYNACONF_NUMBER='@int 123'
export DYNACONF_FLOAT='@float 12.2'
export DYNACONF_FLAG='@bool yes'
export DYNACONF_FLAG2='@bool disabled'
export DYNACONF_LIST='@json [1, 2, 3, 4]'
export DYNACONF_DICT='@json {"name": "Bruno"}'
 

Now you can read all those values from your project and it will be loaded with correct type casting.

现在,您可以从项目中读取所有这些值,并且将使用正确的类型转换将其加载。

真好! 但是我不想使用envvars,因为我使用自动缩放,并且希望我的机器共享设置环境,该怎么做? (Nice! But I don’t want to use envvars because I use autoscaling and I want my machines to share a settings environment how to do it?)

雷迪斯 (Redis)

Go to your settings file (default settings.py) and put

转到您的设置文件(default settings.py )并放入

# connection
REDIS_FOR_DYNACONF = {
    'host': 'localhost',
    'port': 6379,
    'db': 0
}

# and loader
LOADERS_FOR_DYNACONF = [
    'dynaconf.loaders.env_loader',
    'dynaconf.loaders.redis_loader'
]
# connection
REDIS_FOR_DYNACONF = {
    'host': 'localhost',
    'port': 6379,
    'db': 0
}

# and loader
LOADERS_FOR_DYNACONF = [
    'dynaconf.loaders.env_loader',
    'dynaconf.loaders.redis_loader'
]
 

Now you can store settings variables directly in Redis using a hash named by default DYNACONF_DYNACONF

现在您可以使用默认命名为DYNACONF_DYNACONF的哈希将设置变量直接存储在Redis中

If you don’t want want to write directly you can use the Redis writer helper in a python REPL. (ipython as example)

如果您不想直接编写,则可以在python REPL中使用Redis writer帮助器。 (以ipython为例)

And the above will be store in Redis as a hash int the form.

上面的内容将作为哈希int形式存储在Redis中。

DYNACONF_DYNACONF:
    NAME='Bruno'
    MYSQL_HOST='localhost'
    PORT='@int 1234'
DYNACONF_DYNACONF:
    NAME='Bruno'
    MYSQL_HOST='localhost'
    PORT='@int 1234'
 

And of course you can now read those variables in the project, all the casting wildcards also works on Redis but if you want to skip type casting, write as string intead of PORT=1234 use PORT=’1234′ as redis stores everything as string anyway.

当然,您现在可以在项目中读取这些变量,所有强制转换通配符也可以在Redis上使用,但是如果您要跳过类型强制转换,请写为PORT = 1234的字符串intead,请使用PORT ='1234',因为redis将所有内容存储为字符串无论如何。

还有更多 (There is more)

Dynaconf has support for using different namespaces in the same project, you can also write your own loaders, you can find more information on the repository https://github.com/rochacbruno/dynaconf

Dynaconf支持在同一项目中使用不同的名称空间,您还可以编写自己的加载程序,可以在存储库中找到更多信息https://github.com/rochacbruno/dynaconf

有助于 (Contribute)

All contributions are very welcome!!

欢迎所有贡献!!

致谢 (Acknowledgements)

翻译自: https://www.pybloggers.com/2016/02/dynaconf-let-your-settings-to-be-dynamic/

vue动态设置国际化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值