Skip to content

Commit 79dd288

Browse files
alfsbAndré L F S Bacci
authored andcommitted
Creates the do-not-translate mark (#311)
1 parent 46833d4 commit 79dd288

4 files changed

Lines changed: 49 additions & 19 deletions

File tree

docs/editing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Changes in the English version are eventually picked up by the translators.
3838
If a change doesn't affect translations (e.g. fixing a typo in English) then the
3939
commit message should start with `[skip-revcheck]`.
4040

41+
Files that are not to be translated, or copied on translations, should include
42+
an `<?do-not-translate?>` mark.
43+
4144
## Validating your changes
4245
Every time you make changes to documentation sources (both English or translation),
4346
you have to validate your changes to ensure that the manual still builds without error.

scripts/broken.php

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php /*
22
+----------------------------------------------------------------------+
3-
| Copyright (c) 1997-2025 The PHP Group |
3+
| Copyright (c) 1997-2026 The PHP Group |
44
+----------------------------------------------------------------------+
55
| This source file is subject to version 3.01 of the PHP license, |
66
| that is bundled with this package in the file LICENSE, and is |
@@ -38,20 +38,28 @@
3838
$dos2unix = true;
3939
$arg = null;
4040
}
41+
else
42+
$arg = str_replace( '\\' , '/' , $arg );
4143
}
42-
$argv = array_filter( $argv );
44+
$paths = array_filter( $argv );
45+
if ( count( $paths) == 0 )
46+
print_usage_exit();
4347

44-
foreach( $argv as $arg )
48+
foreach( $paths as $path )
4549
{
46-
if ( file_exists( $arg ) )
50+
$dnt = true;
51+
if ( $path == 'en' || str_ends_with( $path , '/en' ) )
52+
$dnt = false;
53+
54+
if ( file_exists( $path ) )
4755
{
48-
if ( is_file( $arg ) )
49-
testFile( $arg );
50-
if ( is_dir( $arg ) )
51-
testDir( $arg );
56+
if ( is_file( $path ) )
57+
testFile( $path , $dnt );
58+
if ( is_dir( $path ) )
59+
testDir( $path , $dnt );
5260
continue;
5361
}
54-
echo "Path does not exist: $arg\n";
62+
echo "Path does not exist: $path\n";
5563
}
5664

5765
function print_usage_exit( $cmd )
@@ -87,7 +95,7 @@ function setup( string & $prefix , string & $suffix , string & $extra )
8795
libxml_clear_errors();
8896
}
8997

90-
function testFile( string $filename , bool $fragment = false )
98+
function testFile( string $filename , bool $checkDnt , bool $fragmentDir = false )
9199
{
92100
$contents = file_get_contents( $filename );
93101

@@ -96,7 +104,7 @@ function testFile( string $filename , bool $fragment = false )
96104
echo "Wrong XML file:\n";
97105
echo " Issue: XML file with BOM. Several tools may misbehave.\n";
98106
echo " Path: $filename\n";
99-
echo " Hint: You can try autofix this with 'doc-base/scripts/broken.php --dos2unix langdir'.\n";
107+
echo " Hint: You can try auto fix this with 'doc-base/scripts/broken.php --dos2unix langdir'.\n";
100108
echo "\n";
101109
autofix_dos2unix( $filename );
102110
}
@@ -106,7 +114,16 @@ function testFile( string $filename , bool $fragment = false )
106114
echo "Wrong XML file:\n";
107115
echo " Issue: XML file contains \\r. Several tools may misbehave.\n";
108116
echo " Path: $filename\n";
109-
echo " Hint: You can try autofix this with 'doc-base/scripts/broken.php --dos2unix langdir'.\n";
117+
echo " Hint: You can try auto fix this with 'doc-base/scripts/broken.php --dos2unix langdir'.\n";
118+
echo "\n";
119+
autofix_dos2unix( $filename );
120+
}
121+
122+
if ( $checkDnt && strpos( $contents , '<?do-not-translate?>' ) !== false )
123+
{
124+
echo "File marked do-not-translate in translation:\n";
125+
echo " Issue: Manual build may fail.\n";
126+
echo " Path: $filename\n";
110127
echo "\n";
111128
autofix_dos2unix( $filename );
112129
}
@@ -121,7 +138,7 @@ function testFile( string $filename , bool $fragment = false )
121138
$doc->substituteEntities = false;
122139
libxml_use_internal_errors( true );
123140

124-
if ( $fragment )
141+
if ( $fragmentDir )
125142
$contents = "<f>{$contents}</f>";
126143
$doc->loadXML( $contents );
127144

@@ -152,18 +169,18 @@ function testFile( string $filename , bool $fragment = false )
152169
}
153170
}
154171

155-
function testDir( string $dir )
172+
function testDir( string $dir , bool $checkDnt )
156173
{
157174
$dir = realpath( $dir );
158175
$files = scandir( $dir );
159-
$fragment = false;
176+
$fragmentDir = false;
160177
$subdirs = [];
161178

162179
foreach( $files as $file )
163180
{
164181
if ( $file == ".xmlfragmentdir" )
165182
{
166-
$fragment = true;
183+
$fragmentDir = true;
167184
continue;
168185
}
169186
if ( $file[0] == "." )
@@ -178,11 +195,11 @@ function testDir( string $dir )
178195
}
179196

180197
if ( str_ends_with( $fullpath , ".xml" ) )
181-
testFile( $fullpath , $fragment );
198+
testFile( $fullpath , $checkDnt , $fragmentDir );
182199
}
183200

184201
foreach( $subdirs as $dir )
185-
testDir( $dir );
202+
testDir( $dir , $checkDnt );
186203
}
187204

188205
function autofix_dos2unix( string $filename )

scripts/translation/lib/RevcheckIgnore.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* +----------------------------------------------------------------------+
4-
* | Copyright (c) 1997-2023 The PHP Group |
4+
* | Copyright (c) 1997-2026 The PHP Group |
55
* +----------------------------------------------------------------------+
66
* | This source file is subject to version 3.01 of the PHP license, |
77
* | that is bundled with this package in the file LICENSE, and is |
@@ -65,4 +65,11 @@ public static function ignore( $filename ) : bool
6565
// At least, do not ignore
6666
return false;
6767
}
68+
69+
public static function mark( $filename )
70+
{
71+
$contents = file_get_contents( $filename );
72+
$skip = strpos( $contents , '<?do-not-translate?>' ) !== false;
73+
return $skip;
74+
}
6875
}

scripts/translation/lib/RevcheckRun.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ private function calculateStatus()
8282

8383
if ( $target == null )
8484
{
85+
if ( RevcheckIgnore::mark( "{$this->sourceDir}/{$source->file}" ) )
86+
continue;
87+
8588
$source->status = RevcheckStatus::Untranslated;
8689
$this->filesUntranslated[] = $source;
8790
$this->addData( $source , null );

0 commit comments

Comments
 (0)