Skip to content

Commit efd58ac

Browse files
committed
By default, do not extract bare text nodes if they contain PHP tags
1 parent d7fa3eb commit efd58ac

File tree

30 files changed

+256
-151
lines changed

30 files changed

+256
-151
lines changed

CHANGES

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Revision history
2121
(like XML parser already does)
2222

2323
- PHP/XHTML parser now treats bare HTML strings (with no wrapper tag)
24-
as translatable by default. This is useful when parsing nested
25-
HTML snippets inside XML or JSON
24+
as translatable by default, except when they contain PHP tags.
25+
This is useful when parsing nested HTML snippets inside XML or JSON
2626

2727
- Parsing errors in nested HTML values inside JSON or XML are now
2828
exposed to the parent parser for proper error reporting

lib/Serge/Engine/Plugin/parse_php_xhtml.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,10 @@ sub analyze_tag_recursively {
419419
$str =~ s/^[\r\n\t ]+//sg;
420420
$str =~ s/[\r\n\t ]+$//sg;
421421

422-
# Only non-empty strings (which are not php blocks) can be translated
422+
# Only non-empty strings which do not contain php blocks can be translated by default
423423

424-
$contains_translatables = 1 if ($str ne '') && ($str !~ m/^__PHP__BLOCK__(\d+)__$/);
424+
$contains_translatables = 1 if $str ne '';
425+
$prohibit_translation = 1 if $str =~ m/\b__PHP__BLOCK__(\d+)__\b/;
425426

426427
#print "** [$name: can=$can_translate, ctr=$contains_translatables] [$str]\n" if $self->{parent}->{debug};
427428
}
Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
items
22
{
3-
0 1 6 4 1 `Page title` NO 0
4-
1 2 8 4 2 NO NO 0
5-
2 3 10 4 3 NO NO 0
6-
3 4 12 4 4 `alt attribute` NO 0
7-
4 5 14 4 5 `title attribute` NO 0
8-
5 6 16 4 6 NO NO 0
9-
6 7 18 4 7 NO NO 0
10-
7 8 20 4 8 NO NO 0
11-
8 9 22 4 9 NO NO 0
12-
9 10 24 4 10 NO NO 0
13-
10 11 26 4 11 NO NO 0
14-
11 12 28 4 12 NO NO 0
15-
12 13 30 4 13 NO NO 0
16-
13 14 32 4 14 NO NO 0
17-
14 15 34 4 15 NO NO 0
18-
15 16 36 4 16 NO NO 0
19-
16 17 38 4 17 NO NO 0
20-
17 18 40 4 18 NO NO 0
21-
18 19 42 4 19 NO NO 0
22-
19 20 44 4 20 NO NO 0
23-
20 21 46 4 21 NO NO 0
3+
0 1 6 4 1 `Page title` NO 0
4+
1 2 8 4 2 NO NO 0
5+
2 3 10 4 3 NO NO 0
6+
3 4 12 4 4 NO NO 0
7+
4 5 14 4 5 NO NO 0
8+
5 6 16 4 6 NO NO 0
9+
6 7 18 4 7 NO NO 0
10+
7 8 20 4 8 NO NO 0
11+
8 9 22 4 9 NO NO 0
2412
}

t/data/engine/parse_php_xhtml/00/reference-output/database/properties

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ properties
33
0 1 source:4 7b5e59f8bb7ad3023335abd269b539b1
44
1 2 hash:4 7b5e59f8bb7ad3023335abd269b539b1
55
2 3 size:4 2601
6-
3 4 items:4
7-
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
8-
4 5 ts:4:test:count 21
9-
5 6 usn:4:test 67
10-
6 7 ts:4:test 3125bc9a2ee5df3a41ba85068093ce13
11-
7 8 target:4:test_job:test 83ee5768900a2bfa7312cbd8bbb08b89
6+
3 4 items:4 1,2,3,4,5,6,7,8,9
7+
4 5 ts:4:test:count 9
8+
5 6 usn:4:test 31
9+
6 7 ts:4:test 1ca0dbb8935e90306222cb5c53aca882
10+
7 8 target:4:test_job:test 89d070812a1ab3e363a09753d35ee0f5
1211
8 9 target:mtime:4:test_job:test 12345678
1312
9 10 source:4:test_job:test 7b5e59f8bb7ad3023335abd269b539b1
1413
10 11 source:ts:4:test_job:test
15-
3125bc9a2ee5df3a41ba85068093ce13
14+
1ca0dbb8935e90306222cb5c53aca882
1615
11 12 job-hash:test_namespace:test_job
1716
80c52c3ab8cfc898775493c6842093a7
1817
12 13 job-plugin:test_namespace:test_job parse_php_xhtml.
Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
strings
22
{
3-
0 1 5 `Sample Page` NO 0
4-
1 2 7 `<img src="x.png" alt="<? echo $pageTitle; ?>" />` NO 0
5-
2 3 9 `<img src="x.png" alt="baz" />` NO 0
6-
3 4 11 `localizable alt attribute text` NO 0
7-
4 5 13 `localizable title attribute text` NO 0
8-
5 6 15 `<img src="x.png" alt="localizable image" />` NO 0
9-
6 7 17 `localizable string 2` NO 0
10-
7 8 19 `Table of Contents` NO 0
11-
8 9 21 `Topic 1` NO 0
12-
9 10 23 `Topic 2` NO 0
13-
10 11 25 `<a href="#topic3">Topic 3</a>` NO 0
14-
11 12 27 `Topic 1` context.1 0
15-
12 13 29 `Paragraph 1` NO 0
16-
13 14 31 `Topic 2` context.1 0
17-
14 15 33 `Paragraph 2` NO 0
18-
15 16 35 `Topic 3` NO 0
19-
16 17 37 `Paragraph 3, Sentence 1.` NO 0
20-
17 18 39 `Paragraph 3, Sentence 2.` NO 0
21-
18 19 41 `Item 1` NO 0
22-
19 20 43 `Item 2` NO 0
23-
20 21 45 `Item 3` NO 0
3+
0 1 5 `Sample Page` NO 0
4+
1 2 7 `<img src="x.png" alt="<? echo $pageTitle; ?>" />` NO 0
5+
2 3 9 `<img src="x.png" alt="baz" />` NO 0
6+
3 4 11 `<img src="x.png" alt="localizable image" />` NO 0
7+
4 5 13 `localizable string 2` NO 0
8+
5 6 15 `Topic 1` NO 0
9+
6 7 17 `Topic 2` NO 0
10+
7 8 19 `Paragraph 3, Sentence 1.` NO 0
11+
8 9 21 `Paragraph 3, Sentence 2.` NO 0
2412
}
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
translations
22
{
3-
0 1 47 1 test `Šáḿṕļē Ṕáğē` NO 0 0
4-
1 2 48 2 test
5-
`<img src="x.png" alt="<? echo $pageTitle; ?>" />` NO 0 0
6-
2 3 49 3 test `<img src="x.png" alt="baz" />` NO 0 0
7-
3 4 50 4 test `ļőçáļĩžáḃļē áļţ áţţŕĩḃũţē ţēҳţ` NO 0 0
8-
4 5 51 5 test `ļőçáļĩžáḃļē ţĩţļē áţţŕĩḃũţē ţēҳţ` NO 0 0
9-
5 6 52 6 test `<img src="x.png" alt="localizable image" />` NO
10-
0 0
11-
6 7 53 7 test `ļőçáļĩžáḃļē šţŕĩŋğ 2` NO 0 0
12-
7 8 54 8 test `Ŧáḃļē őḟ Ćőŋţēŋţš` NO 0 0
13-
8 9 55 9 test `Ŧőṕĩç 1` NO 0 0
14-
9 10 56 10 test `Ŧőṕĩç 2` NO 0 0
15-
10 11 57 11 test `<a href="#topic3">Ŧőṕĩç 3</a>` NO 0 0
16-
11 12 58 12 test `Ŧőṕĩç 1` NO 0 0
17-
12 13 59 13 test `Ṕáŕáğŕáṕĥ 1` NO 0 0
18-
13 14 60 14 test `Ŧőṕĩç 2` NO 0 0
19-
14 15 61 15 test `Ṕáŕáğŕáṕĥ 2` NO 0 0
20-
15 16 62 16 test `Ŧőṕĩç 3` NO 0 0
21-
16 17 63 17 test `Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 1.` NO 0 0
22-
17 18 64 18 test `Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 2.` NO 0 0
23-
18 19 65 19 test `Ĩţēḿ 1` NO 0 0
24-
19 20 66 20 test `Ĩţēḿ 2` NO 0 0
25-
20 21 67 21 test `Ĩţēḿ 3` NO 0 0
3+
0 1 23 1 test `Šáḿṕļē Ṕáğē` NO 0 0
4+
1 2 24 2 test
5+
`<img src="x.png" alt="<? echo $pageTitle; ?>" />` NO 0 0
6+
2 3 25 3 test `<img src="x.png" alt="baz" />` NO 0 0
7+
3 4 26 4 test `<img src="x.png" alt="localizable image" />` NO
8+
0 0
9+
4 5 27 5 test `ļőçáļĩžáḃļē šţŕĩŋğ 2` NO 0 0
10+
5 6 28 6 test `Ŧőṕĩç 1` NO 0 0
11+
6 7 29 7 test `Ŧőṕĩç 2` NO 0 0
12+
7 8 30 8 test `Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 1.` NO 0 0
13+
8 9 31 9 test `Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 2.` NO 0 0
2614
}

t/data/engine/parse_php_xhtml/00/reference-output/localized-resources/test/index.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<p>&copy; 2012 ACME Corporation</p>
1515

1616
<!-- in the following image, 'alt' and 'title' attributes will be extracted -->
17-
<img src="x" alt="ļőçáļĩžáḃļē áļţ áţţŕĩḃũţē ţēҳţ" title="ļőçáļĩžáḃļē ţĩţļē áţţŕĩḃũţē ţēҳţ" />
17+
<img src="x" alt="localizable alt attribute text" title="localizable title attribute text" />
1818

1919
<!-- the following image will be extracted as a whole -->
2020
<img src="x.png" alt="localizable image" />
@@ -34,31 +34,31 @@
3434
<div id="content">
3535
<!-- <h1>..<h7>, <p> and <li> will be translated by default unless the lang="" attribute is set on them -->
3636

37-
<h2>Ŧáḃļē őḟ Ćőŋţēŋţš</h2>
37+
<h2>Table of Contents</h2>
3838
<ul>
3939
<!-- in the following two lines, the <li> will not be translated as it contains
4040
the only <a> tag that is explicitly told to be the translation item -->
4141
<li><a href="#topic1">Ŧőṕĩç 1</a></li>
4242
<li><a href="#topic2">Ŧőṕĩç 2</a></li>
4343

4444
<!-- in the subsequent lines, the <li> item will be the default translation item (default behavior) -->
45-
<li><a href="#topic3">Ŧőṕĩç 3</a></li>
45+
<li><a href="#topic3">Topic 3</a></li>
4646
</ul>
4747

48-
<h2 id="topic1">Ŧőṕĩç 1</h2>
49-
<p>Ṕáŕáğŕáṕĥ 1</p>
48+
<h2 id="topic1">Topic 1</h2>
49+
<p>Paragraph 1</p>
5050

51-
<h2 id="topic2">Ŧőṕĩç 2</h2>
52-
<p>Ṕáŕáğŕáṕĥ 2</p>
51+
<h2 id="topic2">Topic 2</h2>
52+
<p>Paragraph 2</p>
5353

54-
<h2 id="topic2">Ŧőṕĩç 3</h2>
54+
<h2 id="topic2">Topic 3</h2>
5555
<!-- One can manually segment large paragraphs (split them into separate translatable sentences) -->
5656
<p><span>Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 1.</span> <span>Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 2.</span></p>
5757

5858
<ul>
59-
<li>Ĩţēḿ 1</li>
60-
<li>Ĩţēḿ 2</li>
61-
<li>Ĩţēḿ 3</li>
59+
<li>Item 1</li>
60+
<li>Item 2</li>
61+
<li>Item 3</li>
6262
</ul>
6363
</div><!-- /content -->
6464

t/data/engine/parse_php_xhtml/00/reference-output/po/test/index.php.po

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ msgstr "<img src=\"x.png\" alt=\"<? echo $pageTitle; ?>\" />"
2121
msgid "<img src=\"x.png\" alt=\"baz\" />"
2222
msgstr "<img src=\"x.png\" alt=\"baz\" />"
2323

24-
#. alt attribute
25-
#: File: index.php
26-
#: ID: 34425ef5fe06102e2de17ce406e1c917
27-
msgid "localizable alt attribute text"
28-
msgstr "ļőçáļĩžáḃļē áļţ áţţŕĩḃũţē ţēҳţ"
29-
30-
#. title attribute
31-
#: File: index.php
32-
#: ID: 9f0e7bee1fbb5eec8cddb8ebb7d10355
33-
msgid "localizable title attribute text"
34-
msgstr "ļőçáļĩžáḃļē ţĩţļē áţţŕĩḃũţē ţēҳţ"
35-
3624
#: File: index.php
3725
#: ID: e93e6d67a5e03712e87f2d8d93d4fdc4
3826
msgid "<img src=\"x.png\" alt=\"localizable image\" />"
@@ -43,11 +31,6 @@ msgstr "<img src=\"x.png\" alt=\"localizable image\" />"
4331
msgid "localizable string 2"
4432
msgstr "ļőçáļĩžáḃļē šţŕĩŋğ 2"
4533

46-
#: File: index.php
47-
#: ID: 3b31defc07678f0de737043d90f33f00
48-
msgid "Table of Contents"
49-
msgstr "Ŧáḃļē őḟ Ćőŋţēŋţš"
50-
5134
#: File: index.php
5235
#: ID: 40d504f7798cda942b7bd59900e763f4
5336
msgid "Topic 1"
@@ -58,38 +41,6 @@ msgstr "Ŧőṕĩç 1"
5841
msgid "Topic 2"
5942
msgstr "Ŧőṕĩç 2"
6043

61-
#: File: index.php
62-
#: ID: 8ade6d1ffe6fd5970597c73b600252d1
63-
msgid "<a href=\"#topic3\">Topic 3</a>"
64-
msgstr "<a href=\"#topic3\">Ŧőṕĩç 3</a>"
65-
66-
#: File: index.php
67-
#: ID: 996846f8670ab376b53f5ca443e286df
68-
msgctxt "context.1"
69-
msgid "Topic 1"
70-
msgstr "Ŧőṕĩç 1"
71-
72-
#: File: index.php
73-
#: ID: 96bc27974e4e82a218a4d1502938d02d
74-
msgid "Paragraph 1"
75-
msgstr "Ṕáŕáğŕáṕĥ 1"
76-
77-
#: File: index.php
78-
#: ID: 054c21a2169e4b8a80ab5f79dde097d6
79-
msgctxt "context.1"
80-
msgid "Topic 2"
81-
msgstr "Ŧőṕĩç 2"
82-
83-
#: File: index.php
84-
#: ID: bfbc8f478c954b6c5765d5285b655500
85-
msgid "Paragraph 2"
86-
msgstr "Ṕáŕáğŕáṕĥ 2"
87-
88-
#: File: index.php
89-
#: ID: 0cd9b7e2b1d0a17927da40a7a5be599c
90-
msgid "Topic 3"
91-
msgstr "Ŧőṕĩç 3"
92-
9344
#: File: index.php
9445
#: ID: 8f97e74768d7b55d7e02f9195f0c846e
9546
msgid "Paragraph 3, Sentence 1."
@@ -99,18 +50,3 @@ msgstr "Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 1."
9950
#: ID: 54988f57cc86c6ed3c64bd520e18d6f2
10051
msgid "Paragraph 3, Sentence 2."
10152
msgstr "Ṕáŕáğŕáṕĥ 3, Šēŋţēŋçē 2."
102-
103-
#: File: index.php
104-
#: ID: bc36b3a53f73f49726402745eea839d2
105-
msgid "Item 1"
106-
msgstr "Ĩţēḿ 1"
107-
108-
#: File: index.php
109-
#: ID: 9d66bb5198c158d5c883d21e77b4d00a
110-
msgid "Item 2"
111-
msgstr "Ĩţēḿ 2"
112-
113-
#: File: index.php
114-
#: ID: 0f0f255d5c9c92533d5bd889681bf21b
115-
msgid "Item 3"
116-
msgstr "Ĩţēḿ 3"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test for bare HTML without enclosing tags + PHP
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
files
2+
{
3+
0 1 1 test_job test_namespace 1.php 0
4+
1 2 2 test_job test_namespace 2.php 0
5+
2 3 3 test_job test_namespace 3.php 0
6+
3 4 10 test_job test_namespace 4.php 0
7+
4 5 13 test_job test_namespace 5.php 0
8+
}

0 commit comments

Comments
 (0)