Pybabel JSon Metdef(MD)Gettext strings extractor
PyBabel-json-md的Python项目详细描述
发行说明
- 0.1.0-初始版本
pybabel json md松散地基于由anton bykov编写的pybabel json。在处理json文件的解析以及处理键和省略ngettext函数的方式上,很多逻辑都是不同的,但是,我们希望将这归功于它的前身。代码的变化足够大,足以保证新的版本,而不是试图对原始版本进行更改。
pybabel json md的md部分引用metadef(即元数据定义),如下所述: Openstack Metadata Definitions Catalog
这个babel插件旨在与openstack glass i18n一起用于glass的元数据定义目录。
安装
pip安装pybabel json md
用法
将[json-md:path/**.json]添加到babel配置文件(例如,babel.cfg)
(可选)添加一个“名称列表”以指定要筛选的名称:
name_list=显示姓名、说明、标题
与Pybabel一起运行:
pybabel extract-f babel.cfg-o sample.pot metadef json文件的路径
主要功能
默认情况下,将返回所有有效key:value对的value部分。
还支持字符串列表。
如果指定“name_list”选项,程序将只返回与name_list中提供的密钥名称相关联的字符串值。
在上面的用法示例中,程序将返回与任何出现的键“display_name”、“description”和“title”相关联的字符串值。密钥名应该只是与值或列表直接对应的密钥(即不支持完整路径密钥名)。
当使用上面给出的name_list选项以及下面的示例json文件时,babel写出的msgid的次数是1+22-3次。注意:22是pybabel json md返回的匹配数,但是,-3是因为版本、管理用户和管理用户描述各重复一次,而babel将各自报告为一个msgid。1是babel在pot文件开头写出的初始“dummy”msgid。
metadef json文件示例
{"namespace":"OS::Software::Test","display_name":"Test OS Software","description":"Test software description (protected = false).","visibility":"public","protected":false,"resource_type_associations":[{"name":"OS::Glance::Image"},{"name":"OS::Cinder::Volume","properties_target":"image"},{"name":"OS::Nova::Instance"}],"objects":[{"name":"MySQL","description":"MySQL software desc.","properties":{"sw_database_mysql_version":{"title":"Version","description":"The specific version of MySQL.","type":"string"},"sw_database_mysql_listen_port":{"title":"Listen Port","description":"The configured TCP/IP port which MySQL listens...","type":"integer","minimum":1,"maximum":65535,"default":3606},"sw_database_mysql_admin":{"title":"Admin User","description":"The primary user with privileges...","type":"string","default":"root"}}},{"name":"SQL Server","description":"SQL Server is an RDBMS from MS.","properties":{"sw_database_sqlserver_version":{"title":"Version","description":"The specific version of Microsoft SQL Server.","type":"string"},"sw_database_sqlserver_edition":{"title":"Edition","description":"SQL Server is available in multiple editions.","type":"string","default":"Express","enum":["Datacenter","Enterprise","Web","Express","Datawarehouse Appliance Edition"]},"sw_database_sqlserver_admin":{"title":"Admin User","description":"The primary user with privileges...","type":"string","default":"sa"}}}],"properties":{"guest_sockets":{"title":"vCPU Sockets","description":"Preferred number of sockets to expose to the guest.","type":"integer"},"guest_cores":{"title":"vCPU Cores","description":"Preferred number of cores to expose to the guest.","type":"integer"},"guest_threads":{"title":"vCPU Threads","description":"Preferred number of threads to expose to the guest.","type":"integer"}},"tags":[{"name":"tag1-test"},{"name":"tag2-test"}]}