Skip to content

Commit 4ca082b

Browse files
alfsbAndré L F S Baccijordikroon
authored
Enable XML Text Entities (#301)
* Enable text entities on configure.php * Idempotent filenames for individual/slow files * Does not show untranslated warnings with only one language * Document entity files names/functions * Update scripts/text-entities.php * Review changes * Rewrite in preparation for entity files on doc-lang/reference/ * Enable grouped entities inside doc-lang/reference Co-authored-by: André L F S Bacci <ae@php.net> Co-authored-by: Jordi Kroon <jordi@jordikroon.nl>
1 parent 5b17025 commit 4ca082b

10 files changed

Lines changed: 589 additions & 472 deletions

configure.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,11 @@ function git_status()
551551
echo "\n" , trim( $output ) . "\n\n";
552552
}
553553

554-
// DTD layer before first XML loading
554+
// DTD entity layer before first XML loading
555555

556556
dtd_conf_entities();
557557
dtd_file_entities();
558+
dtd_text_entities();
558559

559560
function dtd_conf_entities()
560561
{
@@ -564,22 +565,16 @@ function dtd_conf_entities()
564565

565566
$conf[] = "<!ENTITY LANG '$lang'>";
566567

567-
if ( $lang == 'en' )
568-
{
569-
realpain( __DIR__ . "/temp/empty" , touch: true );
570-
$trans1 = realpain( __DIR__ . "/temp/empty" );
571-
$trans2 = realpain( __DIR__ . "/temp/empty" );
572-
$trans3 = realpain( __DIR__ . "/temp/empty" );
573-
}
574-
else
568+
if ( $lang != 'en' )
575569
{
576570
$trans1 = realpain( __DIR__ . "/../$lang/language-defs.ent" );
577571
$trans2 = realpain( __DIR__ . "/../$lang/language-snippets.ent" );
578572
$trans3 = realpain( __DIR__ . "/../$lang/extensions.ent" );
573+
574+
$conf[] = "<!ENTITY % translation-defs SYSTEM '$trans1'>";
575+
$conf[] = "<!ENTITY % translation-snippets SYSTEM '$trans2'>";
576+
$conf[] = "<!ENTITY % translation-extensions SYSTEM '$trans3'>";
579577
}
580-
$conf[] = "<!ENTITY % translation-defs SYSTEM '$trans1'>";
581-
$conf[] = "<!ENTITY % translation-snippets SYSTEM '$trans2'>";
582-
$conf[] = "<!ENTITY % translation-extensions SYSTEM '$trans3'>";
583578

584579
if ( $ac['CHMENABLED'] == 'yes' )
585580
{
@@ -589,7 +584,7 @@ function dtd_conf_entities()
589584
else
590585
$conf[] = "<!ENTITY manual.chmonly ''>";
591586

592-
file_put_contents( __DIR__ . "/temp/manual.conf" , implode( "\n" , $conf ) );
587+
file_put_contents( __DIR__ . "/temp/manual.inc" , implode( "\n" , $conf ) );
593588
}
594589

595590
function dtd_file_entities()
@@ -620,6 +615,30 @@ function dtd_file_entities()
620615
}
621616
}
622617

618+
function dtd_text_entities()
619+
{
620+
global $ac;
621+
$php = $ac['PHP'];
622+
$lang = $ac["LANG"];
623+
624+
$parts = [ $php
625+
, __DIR__ . "/scripts/text-entities.php"
626+
, "en" ];
627+
if ( $lang != "en" )
628+
$parts[] = $lang;
629+
630+
foreach ( $parts as & $part )
631+
$part = escapeshellarg( $part );
632+
$cmd = implode( ' ' , $parts );
633+
$ret = 0;
634+
passthru( $cmd , $ret );
635+
636+
if ( $ret != 0 )
637+
{
638+
echo "doc-base/scripts/entities.php FAILED.\n";
639+
exit( 1 );
640+
}
641+
}
623642

624643
checking("for if we should generate a simplified file");
625644
if ($ac["GENERATE"] != "no") {

entities/global.ent-dist

Lines changed: 0 additions & 19 deletions
This file was deleted.

entities/manual.ent-dist

Lines changed: 0 additions & 14 deletions
This file was deleted.

entities/normal.ent-dist

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf8" ?>
2+
<!-- $Revision:$ -->
3+
<!--
4+
5+
# Description
6+
7+
This is a "normal" XML Entity file.
8+
See doc-base/script/text-entities.php for details.
9+
10+
Place here small entities that are expected to be translated.
11+
For big or complex entities, please create an individual entity
12+
file at doc-lang/entities/entityname.xml.
13+
14+
# Examples
15+
16+
<entity name="name">Direct text</entity>
17+
18+
<entity name="name.name">
19+
Single-, multi- or text rooted XML fragment, as long as it is
20+
a well-balanced one. Mind the XML namespaces of the root XML
21+
element below.
22+
</entity>
23+
24+
-->
25+
26+
<entities xmlns = "http://docbook.org/ns/docbook"
27+
xmlns:xlink = "http://www.w3.org/1999/xlink"
28+
translate = "yes">
29+
30+
31+
</entities>

entities/remove.ent-dist

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
<?xml version="1.0" encoding="utf8" ?>
1+
<?xml version="1.0" encoding="utf8" ?><?phprevcheck no ?>
2+
<!-- $Revision:$ -->
23
<!--
3-
This is a "remove" XML Entity file.
4-
See doc-base/script/entities.php for details.
54
6-
Place here only deprecated entities that are expected NOT
7-
be being used in any part of the manual.
5+
# Description
86
9-
DO NOT COPY OR TRANSLATE THIS FILE.
7+
This is a "remove" XML Entity file.
8+
See doc-base/script/text-entities.php for details.
9+
10+
Place here only deprecated entities that are expected NOT
11+
be being used in any part of the manual.
12+
13+
DO NOT COPY OR TRANSLATE THIS FILE.
14+
15+
If an entity moved here is used in a language in your control,
16+
this means that the entity on the original file is planned to be
17+
removed, or already was removed.
18+
19+
# Examples
20+
21+
<entity name="name"></entity>
22+
23+
<entity name="name.name">
24+
It may be necessary to preserve the original body to avoid
25+
breakage in manual translations.
26+
</entity>
1027
11-
If an entity moved here is used in a language in your control,
12-
this means that the entity on the original file is planned to be
13-
removed, or already was removed. Consult the original text file
14-
and apply changes accordly.
1528
-->
16-
<entities xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
1729

18-
<!-- <entity name="ent.name">XML fragment</entity> -->
30+
<entities xmlns = "http://docbook.org/ns/docbook"
31+
xmlns:xlink = "http://www.w3.org/1999/xlink"
32+
translate = "remove">
33+
34+
1935

2036
</entities>

entities/unique.ent-dist

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf8" ?><?phprevcheck no ?>
2+
<!-- $Revision:$ -->
3+
<!--
4+
5+
# Description
6+
7+
This is a "unique" XML Entity file.
8+
See doc-base/script/text-entities.php for details.
9+
10+
Place here only small entities that are expected NOT
11+
being translated in any part of the manual.
12+
13+
DO NOT COPY OR TRANSLATE THIS FILE.
14+
15+
If you want/need to translate some entity placed here,
16+
open an issue on doc-base or doc-en repository, so the
17+
translatable entity is moved to a normal entity file.
18+
19+
# Examples
20+
21+
<entity name="name">Direct text</entity>
22+
23+
<entity name="name.name">
24+
Single-, multi- or text rooted XML fragment, as long as it is
25+
a well-balanced one. Mind the XML namespaces of <entities>
26+
XML element below.
27+
</entity>
28+
29+
-->
30+
31+
<entities xmlns = "http://docbook.org/ns/docbook"
32+
xmlns:xlink = "http://www.w3.org/1999/xlink"
33+
translate = "no">
34+
35+
36+
37+
</entities>

manual.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!DOCTYPE PHPDOC [
33

44
<!-- Parameter entities used to configure manual.xml -->
5-
<!ENTITY % configure SYSTEM "./temp/manual.conf">
5+
<!ENTITY % configure SYSTEM "./temp/manual.inc">
66
%configure;
77

88
<!-- Entities collected by entities.php -->

0 commit comments

Comments
 (0)