Permalink
Browse files

add line numbers support.

adopted [patch](https://sourceforge.net/p/smarty-gettext/patches/3/) from old project
  • Loading branch information...
1 parent d08b3fb commit f13bd14947ec3e0ca9eff5a5e65e78fb661f1be2 @glensc committed Nov 22, 2013
Showing with 23 additions and 10 deletions.
  1. +6 −0 ChangeLog.md
  2. +2 −2 tests/data/1.pot
  3. +3 −3 tests/data/2.pot
  4. +12 −5 tsmarty2c.php
View
@@ -1,3 +1,9 @@
+## 1.0.x (not released)
+
+IMPROVEMENTS:
+
+ - add line numbers support. adopted [patch](https://sourceforge.net/p/smarty-gettext/patches/3/) from old project
+
## 1.0.1 (2013-11-21)
IMPROVEMENTS:
View
@@ -1,11 +1,11 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
-#: <DATADIR>/1.html
+#: <DATADIR>/1.html:2
msgid "my name is %1"
msgstr ""
-#: <DATADIR>/1.html
+#: <DATADIR>/1.html:8
msgid ""
"The 1st parameter is %1, the 2nd is %2\n"
"and the 3nd %3."
View
@@ -1,14 +1,14 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
-#: <DATADIR>/2.html
+#: <DATADIR>/2.html:4
msgid "Hello, %1"
msgstr ""
-#: <DATADIR>/2.html
+#: <DATADIR>/2.html:5
msgid "What I'm following (%1)"
msgstr ""
-#: <DATADIR>/2.html
+#: <DATADIR>/2.html:6
msgid "... in category %1"
msgstr ""
View
@@ -64,6 +64,10 @@ function fs($str) {
return $str;
}
+function lineno_from_offset($content, $offset) {
+ return substr_count($content, "\n", 0, $offset) + 1;
+}
+
function msgmerge($outfile, $data) {
// skip empty
if (empty($data)) {
@@ -103,19 +107,22 @@ function do_file($outfile, $file) {
preg_match_all(
"/{$ldq}\s*({$cmd})\s*([^{$rdq}]*){$rdq}+([^{$ldq}]*){$ldq}\/\\1{$rdq}/",
$content,
- $matches
+ $matches,
+ PREG_OFFSET_CAPTURE
);
$msgids = array();
$msgids_plural = array();
for ($i = 0; $i < count($matches[0]); $i++) {
- if (preg_match('/plural\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i], $match)) {
- $msgid = $matches[3][$i];
+ if (preg_match('/plural\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i][0], $match)) {
+ $msgid = $matches[3][$i][0];
$msgid_plural[$msgid] = $match[1];
} else {
- $msgid = $matches[3][$i];
+ $msgid = $matches[3][$i][0];
}
- $msgids[$msgid][] = $file;
+
+ $lineno = lineno_from_offset($content, $matches[2][$i][1]);
+ $msgids[$msgid][] = "$file:$lineno";
}
ob_start();

0 comments on commit f13bd14

Please sign in to comment.