Skip to content

Commit

Permalink
fix TypeError with numeric strings #265
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 20, 2020
1 parent a764e91 commit 8ef05a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Generator/MoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function generateString(Translations $translations): string

$originalsIndex[] = [
'relativeOffset' => strlen($originalsTable),
'length' => strlen($originalString),
'length' => strlen((string) $originalString),
];
$originalsTable .= $originalString."\x00";
$translationsIndex[] = [
Expand Down
8 changes: 6 additions & 2 deletions tests/MoGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testMoGenerator()
->set('X-Generator', 'PHP-Gettext');

$translation = Translation::create('context-1', 'Original');
$translation->translate('Orixintal');
$translation->translate('Orixinal');
$translations->add($translation);

$translation = Translation::create('context-1', 'Other comment', 'Other comments');
Expand All @@ -36,14 +36,18 @@ public function testMoGenerator()
$translation->translate('Comentario deshabilitado');
$translations->add($translation);

$translation = Translation::create(null, '123456');
$translation->translate('12345');
$translations->add($translation);

$mo = $generator->generateString($translations);
$expected = file_get_contents(__DIR__.'/assets/mo-generator-result.mo');

$this->assertSame($expected, $mo);

$result = $loader->loadString($mo);

$this->assertCount(2, $result);
$this->assertCount(3, $result);
$this->assertCount(5, $result->getHeaders());
}
}
Binary file modified tests/assets/mo-generator-result.mo
Binary file not shown.

0 comments on commit 8ef05a5

Please sign in to comment.