Skip to content

Commit 1dfdfa9

Browse files
committed
Merge branch 'master' of https://github.com/oscarotero/Gettext into po_line_breaks
2 parents bec6d36 + 241899f commit 1dfdfa9

25 files changed

Lines changed: 692 additions & 121 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: php
22
sudo: false
3+
dist: trusty
34

45
env:
56
- COMPOSER_DISABLE_XDEBUG_WARN=1

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
Previous releases are documented in [github releases](https://github.com/oscarotero/Gettext/releases)
99

10+
## [4.7.0] - Unreleased
11+
### Added
12+
- Support for UnitID in Xliff [#221]
13+
- Support for scan multiple domains at the same time [#223]
14+
1015
## [4.6.3] - 2019-07-15
1116
### Added
1217
- Some VueJs extraction improvements and additions [#205], [#213]
@@ -122,7 +127,10 @@ Previous releases are documented in [github releases](https://github.com/oscarot
122127
[#213]: https://github.com/oscarotero/Gettext/issues/213
123128
[#214]: https://github.com/oscarotero/Gettext/issues/214
124129
[#215]: https://github.com/oscarotero/Gettext/issues/215
130+
[#221]: https://github.com/oscarotero/Gettext/issues/221
131+
[#223]: https://github.com/oscarotero/Gettext/issues/223
125132

133+
[4.7.0]: https://github.com/oscarotero/Gettext/compare/v4.6.3...HEAD
126134
[4.6.3]: https://github.com/oscarotero/Gettext/compare/v4.6.2...v4.6.3
127135
[4.6.2]: https://github.com/oscarotero/Gettext/compare/v4.6.1...v4.6.2
128136
[4.6.1]: https://github.com/oscarotero/Gettext/compare/v4.6.0...v4.6.1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Gettext\Extractors;
4+
5+
use Gettext\Translations;
6+
7+
interface ExtractorMultiInterface
8+
{
9+
/**
10+
* Parses a string and append the translations found in the Translations instance.
11+
* Allows scanning for multiple domains at a time (each Translation has to have a different domain)
12+
*
13+
* @param string $string
14+
* @param Translations[] $translations
15+
* @param array $options
16+
*/
17+
public static function fromStringMultiple($string, array $translations, array $options = []);
18+
19+
/**
20+
* Parses a string and append the translations found in the Translations instance.
21+
* Allows scanning for multiple domains at a time (each Translation has to have a different domain)
22+
*
23+
* @param $file
24+
* @param Translations[] $translations
25+
* @param array $options
26+
*/
27+
public static function fromFileMultiple($file, array $translations, array $options = []);
28+
}

src/Extractors/JsCode.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace Gettext\Extractors;
44

5+
use Exception;
56
use Gettext\Translations;
67
use Gettext\Utils\JsFunctionsScanner;
78

89
/**
910
* Class to get gettext strings from javascript files.
1011
*/
11-
class JsCode extends Extractor implements ExtractorInterface
12+
class JsCode extends Extractor implements ExtractorInterface, ExtractorMultiInterface
1213
{
1314
public static $options = [
1415
'constants' => [],
@@ -36,14 +37,35 @@ class JsCode extends Extractor implements ExtractorInterface
3637
];
3738

3839
/**
39-
* {@inheritdoc}
40-
* @throws \Exception
40+
* @inheritdoc
41+
* @throws Exception
4142
*/
4243
public static function fromString($string, Translations $translations, array $options = [])
44+
{
45+
self::fromStringMultiple($string, [$translations], $options);
46+
}
47+
48+
/**
49+
* @inheritDoc
50+
* @throws Exception
51+
*/
52+
public static function fromStringMultiple($string, array $translations, array $options = [])
4353
{
4454
$options += static::$options;
4555

4656
$functions = new JsFunctionsScanner($string);
4757
$functions->saveGettextFunctions($translations, $options);
4858
}
59+
60+
/**
61+
* @inheritDoc
62+
* @throws Exception
63+
*/
64+
public static function fromFileMultiple($file, array $translations, array $options = [])
65+
{
66+
foreach (self::getFiles($file) as $file) {
67+
$options['file'] = $file;
68+
static::fromStringMultiple(self::readFile($file), $translations, $options);
69+
}
70+
}
4971
}

src/Extractors/PhpCode.php

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
namespace Gettext\Extractors;
44

5+
use Exception;
56
use Gettext\Translations;
67
use Gettext\Utils\PhpFunctionsScanner;
78

89
/**
910
* Class to get gettext strings from php files returning arrays.
1011
*/
11-
class PhpCode extends Extractor implements ExtractorInterface
12+
class PhpCode extends Extractor implements ExtractorInterface, ExtractorMultiInterface
1213
{
1314
public static $options = [
14-
// - false: to not extract comments
15-
// - empty string: to extract all comments
16-
// - non-empty string: to extract comments that start with that string
17-
// - array with strings to extract comments format.
15+
// - false: to not extract comments
16+
// - empty string: to extract all comments
17+
// - non-empty string: to extract comments that start with that string
18+
// - array with strings to extract comments format.
1819
'extractComments' => false,
1920

2021
'constants' => [],
@@ -43,8 +44,18 @@ class PhpCode extends Extractor implements ExtractorInterface
4344

4445
/**
4546
* {@inheritdoc}
47+
* @throws Exception
4648
*/
4749
public static function fromString($string, Translations $translations, array $options = [])
50+
{
51+
self::fromStringMultiple($string, [$translations], $options);
52+
}
53+
54+
/**
55+
* @inheritDoc
56+
* @throws Exception
57+
*/
58+
public static function fromStringMultiple($string, array $translations, array $options = [])
4859
{
4960
$options += static::$options;
5061

@@ -57,6 +68,18 @@ public static function fromString($string, Translations $translations, array $op
5768
$functions->saveGettextFunctions($translations, $options);
5869
}
5970

71+
/**
72+
* @inheritDoc
73+
*/
74+
public static function fromFileMultiple($file, array $translations, array $options = [])
75+
{
76+
foreach (self::getFiles($file) as $file) {
77+
$options['file'] = $file;
78+
static::fromStringMultiple(self::readFile($file), $translations, $options);
79+
}
80+
}
81+
82+
6083
/**
6184
* Decodes a T_CONSTANT_ENCAPSED_STRING string.
6285
*
@@ -110,7 +133,11 @@ function ($match) {
110133
);
111134
}
112135

113-
//http://php.net/manual/en/function.chr.php#118804
136+
/**
137+
* @param $dec
138+
* @return string|null
139+
* @see http://php.net/manual/en/function.chr.php#118804
140+
*/
114141
private static function unicodeChar($dec)
115142
{
116143
if ($dec < 0x80) {
@@ -119,20 +146,22 @@ private static function unicodeChar($dec)
119146

120147
if ($dec < 0x0800) {
121148
return chr(0xC0 + ($dec >> 6))
122-
.chr(0x80 + ($dec & 0x3f));
149+
. chr(0x80 + ($dec & 0x3f));
123150
}
124151

125152
if ($dec < 0x010000) {
126153
return chr(0xE0 + ($dec >> 12))
127-
.chr(0x80 + (($dec >> 6) & 0x3f))
128-
.chr(0x80 + ($dec & 0x3f));
154+
. chr(0x80 + (($dec >> 6) & 0x3f))
155+
. chr(0x80 + ($dec & 0x3f));
129156
}
130157

131158
if ($dec < 0x200000) {
132159
return chr(0xF0 + ($dec >> 18))
133-
.chr(0x80 + (($dec >> 12) & 0x3f))
134-
.chr(0x80 + (($dec >> 6) & 0x3f))
135-
.chr(0x80 + ($dec & 0x3f));
160+
. chr(0x80 + (($dec >> 12) & 0x3f))
161+
. chr(0x80 + (($dec >> 6) & 0x3f))
162+
. chr(0x80 + ($dec & 0x3f));
136163
}
164+
165+
return null;
137166
}
138167
}

0 commit comments

Comments
 (0)