1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
<?php
/*
+----------------------------------------------------------------------+
| Copyright (c) 1997-2023 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net, so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Philip Olson <philip@php.net> |
| Some code stolen from other phpdoc/scripts/ |
+----------------------------------------------------------------------+
$Id$
Introduction:
This library is used by translation related scripts within
the PHP Documentation repository.
Usage examples:
// Should this file be translated?
if (!is_translatable ($filename)) {
exit;
}
// Is the translation considered current?
if (!is_translation_current ($file_en, $file_lang)) {
exit;
}
*/
function is_translation_current ($filename_en, $filename_lang) {
if (!is_readable ($filename_en)) {
trigger_error("File ($filename_en) is not readable", E_USER_WARNING);
return false;
}
if (!is_readable ($filename_lang)) {
trigger_error("File ($filename_lang) is not readable", E_USER_WARNING);
return false;
}
$en = file_get_contents($filename_en);
$lang = file_get_contents($filename_lang);
$match_en = $match_lang = array();
preg_match ("/<!-- .Revision: (\d+) . -->/", $en, $match_en);
preg_match ("/<!--\s*EN-Revision:\s*(\d+)\s*/", $lang, $match_lang);
if (empty($match_en[1]) || empty($match_lang[1])) {
trigger_error("Cannot extract Revision info for (LANG: $filename_lang) (EN: $filename_lang)", E_USER_WARNING);
return false;
}
if (trim($match_en[1]) === trim($match_lang[1])) {
return true;
}
return false;
}
function is_translatable ($filename) {
$files_not_translated = array(
'rsusi.txt',
'missing-ids.xml',
'extensions.xml',
'README',
'contributors.xml',
'contributors.ent',
'reserved.constants.xml',
'DO_NOT_TRANSLATE',
'license.xml',
'versions.xml',
);
if (in_array(basename($filename), $files_not_translated)) {
return false;
}
// Exclude entity files generated by PhD
if (preg_match("/^entities\./", basename($filename))) {
return false;
}
$files_matches = array('/internals/', '/internals2/');
foreach ($files_matches as $match) {
if (false !== strpos($filename, $match)) {
return false;
}
}
return true;
}
|