diff --git a/potx.inc b/potx.inc index c2527df..d2ac952 100644 --- a/potx.inc +++ b/potx.inc @@ -1283,6 +1283,12 @@ function _potx_find_context($tf, $ti, $file, $function_name) { (_potx_is_end_of_array($_potx_tokens[$ti]) && $nesting == -1))) { $ti++; if (!is_array($_potx_tokens[$ti])) { + // Treat each () and [] pair as going into / out of nesting levels. + // There may be function or method calls as well as nested short + // arrays within the arguments list. The list may be similar to: + // array('langcode' => $obj->someMethod([])[2], 'context' => 'Long month name') + // or + // ['langcode' => $obj->someMethod(array())[2], 'context' => 'Long month name'] if ($_potx_tokens[$ti] == ')' || $_potx_tokens[$ti] == ']') { $nesting--; } diff --git a/tests/potx.test b/tests/potx.test index 44ca2aa..1df2b9d 100644 --- a/tests/potx.test +++ b/tests/potx.test @@ -266,12 +266,12 @@ class PotxTestCase extends DrupalWebTestCase { $this->assertMsgIDContext('TranslationWrapper string with context', 'With context'); $this->assertMsgID('TranslatableMarkup string'); - $this->assertMsgIDContext('TranslatableMarkup string with context', 'With context'); $this->assertMsgID('TranslatableMarkup string without context'); $this->assertMsgIDContext('TranslatableMarkup string with long array context', 'With context'); $this->assertMsgIDContext('TranslatableMarkup string with short array context', 'With context'); $this->assertMsgIDContext('TranslatableMarkup string with long array followed by short array context', 'With context'); $this->assertMsgIDContext('TranslatableMarkup string with complicated tokens', 'With context'); + $this->assertMsgIDContext('TranslatableMarkup string with complicated option tokens', 'With context'); $this->assertMsgID('Test translatable string inside an inline template'); $this->assertMsgID('Another test translatable string inside an inline template'); diff --git a/tests/potx_test_8.module.txt b/tests/potx_test_8.module.txt index d9dacca..0ad13be 100644 --- a/tests/potx_test_8.module.txt +++ b/tests/potx_test_8.module.txt @@ -26,6 +26,7 @@ function potx_test_8_example() { $d = new TranslatableMarkup('TranslatableMarkup string with short array context', [], ['context' => 'With context']); $e = new TranslatableMarkup('TranslatableMarkup string with long array followed by short array context', array(), ['context' => 'With context']); $f = new TranslatableMarkup('TranslatableMarkup string with complicated tokens', array([], 2, potx_test_8_sample(), array(), [[]]), ['context' => 'With context']); + $g = new TranslatableMarkup('TranslatableMarkup string with complicated option tokens', [], ['foo' => potx_test_8_sample([4]), 'bar' => [12, 14, []], 'context' => 'With context', 'eek' => 'ook']); $a->debug('Debug message'); $b->info('Info message');