Skip to content

Commit

Permalink
Fixing an small error with token parsing, tests added. Refs #333.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Feb 12, 2010
1 parent f6f04b6 commit 5653c72
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cake/console/libs/tasks/extract.php
Expand Up @@ -264,7 +264,7 @@ function __parse($functionName, $map) {
$count = 0;
$tokenCount = count($this->__tokens);

while (($tokenCount - $count) > 7) {
while (($tokenCount - $count) > 1) {
list($countToken, $firstParenthesis) = array($this->__tokens[$count], $this->__tokens[$count + 1]);
if (!is_array($countToken)) {
$count++;
Expand Down Expand Up @@ -321,12 +321,12 @@ function __parse($functionName, $map) {
function __buildFiles() {
foreach ($this->__strings as $domain => $strings) {
foreach ($strings as $string => $files) {
$occurances = array();
$occurences = array();
foreach ($files as $file => $lines) {
$occurances[] = $file . ':' . implode(';', $lines);
$occurences[] = $file . ':' . implode(';', $lines);
}
$occurances = implode("\n#: ", $occurances);
$header = '#: ' . str_replace($this->__paths, '', $occurances) . "\n";
$occurences = implode("\n#: ", $occurences);
$header = '#: ' . str_replace($this->__paths, '', $occurences) . "\n";

if (strpos($string, "\0") === false) {
$sentence = "msgid \"{$string}\"\n";
Expand Down
13 changes: 10 additions & 3 deletions cake/tests/cases/console/libs/tasks/extract.test.php
Expand Up @@ -126,9 +126,17 @@ function testExecute() {
$this->assertPattern($pattern, $result);

// extract.ctp
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
$pattern = '/\#: (\\\\|\/)extract\.ctp:6\n';
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
$this->assertPattern($pattern, $result);
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';

$pattern = '/\#: (\\\\|\/)extract\.ctp:7\n';
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
$this->assertPattern($pattern, $result);

$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
$pattern .= '\#: (\\\\|\/)home\.ctp:74\n';
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
$this->assertPattern($pattern, $result);

// extract.ctp - reading the domain.pot
Expand All @@ -144,7 +152,6 @@ function testExecute() {
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
$this->assertPattern($pattern, $result);


$Folder = new Folder($path);
$Folder->delete();
}
Expand Down
7 changes: 5 additions & 2 deletions cake/tests/test_app/views/pages/extract.ctp
@@ -1,11 +1,14 @@
<?php
$count = 10;
$message = array('count' => 10);
$messages = array('count' => 10);

// Plural
__n('You have %d new message.', 'You have %d new messages.', $count);
__n('You deleted %d message.', 'You deleted %d messages.', $messages['count']);

// Domain Plural
__dn('domain', 'You have %d new message (domain).', 'You have %d new messages (domain).', '10');
__dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages (domain).', $messages['count']);
__dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages (domain).', $messages['count']);

// Duplicated Message
__('Editing this Page');

0 comments on commit 5653c72

Please sign in to comment.