diff --git a/potx.inc b/potx.inc index b80e86b..2ec2280 100644 --- a/potx.inc +++ b/potx.inc @@ -1874,6 +1874,9 @@ function _potx_parse_yaml_file($code, $file_name, $save_callback) { elseif (substr($file_name, -15) === '.links.menu.yml') { _potx_find_menu_links_yml_file_strings($code, $file_name, $save_callback); } + elseif (substr($file, -16) === '.permissions.yml') { + _potx_find_permissions_file_strings($code, $file_name, $save_callback); + } // Handle configuration schema files, found in config/schema directories. elseif (preg_match('~config/schema/[^/]+\.schema\.yml$~', $file_name)) { $schema = Yaml::parse($code); @@ -1993,6 +1996,28 @@ function _potx_find_menu_links_yml_file_strings($code, $file_name, $save_callbac } /** + * Parse a .permissions.yml file, and add relevant strings to the list. + */ +function _potx_find_permissions_file_strings($code, $file_name, $save_callback, $api_version = POTX_API_CURRENT) { + $info = Yaml::parse($code); + + // Menu links contain a title and an optional title_context, as well as an + // optional description, which should be translated. + foreach ($info as $key => $value) { + if (is_array($value) && array_key_exists('title', $value)) { + $save_callback($value['title'], POTX_CONTEXT_NONE, $file_name); + } + if (is_array($value) && array_key_exists('description', $value)) { + $save_callback($value['description'], POTX_CONTEXT_NONE, $file_name); + } + // We do have a simple permission. + if (!is_array($value)) { + $save_callback($value, POTX_CONTEXT_NONE, $file_name); + } + } +} + +/** * Detect validation constraint messages. Drupal 8+ * * This sequences is searched for: diff --git a/tests/potx.test b/tests/potx.test index 790fe18..b1a80ee 100644 --- a/tests/potx.test +++ b/tests/potx.test @@ -338,6 +338,16 @@ class PotxTestCase extends DrupalWebTestCase { } /** + * Test parsing of Drupal 8 permissions files. + */ + public function testDrupal8PermissionsYml() { + $this->parseFile(drupal_get_path('module', 'potx'). '/tests/potx_test_8.permissions.yml', POTX_API_8); + $this->assertMsgID('Title potx_test_8_a'); + $this->assertMsgID('Description: potx_test_8_a'); + $this->assertMsgID('Title potx_test_8_b'); + } + + /** * Test parsing of Drupal 8 configuration schema files. */ public function testDrupal8ConfigurationSchema() { diff --git a/tests/potx_test_8.permissions.yml b/tests/potx_test_8.permissions.yml new file mode 100644 index 0000000..a38a200 --- /dev/null +++ b/tests/potx_test_8.permissions.yml @@ -0,0 +1,4 @@ +"potx_test_8 permission a": + title: 'Title potx_test_8_a' + description: 'Description: potx_test_8_a' +potx_test_8_permission_b: 'Title potx_test_8_b'