82 lines
2 KiB
PHP
82 lines
2 KiB
PHP
<?php
|
|
/**
|
|
* استخراج رشتههای دامنهٔ hesabix2 به hesabix2.pot — فقط توسعه/CI.
|
|
*
|
|
* php languages/extract-pot.php
|
|
*/
|
|
|
|
$theme_dir = dirname( __DIR__ );
|
|
$msgs = array();
|
|
|
|
function hesabix2_pot_escape_line( string $msg ): string {
|
|
return str_replace( array( "\r\n", "\n", "\r" ), '\\n ', $msg );
|
|
}
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator( $theme_dir, FilesystemIterator::SKIP_DOTS )
|
|
);
|
|
|
|
foreach ( $iterator as $f ) {
|
|
if ( ! $f->isFile() || strtolower( $f->getExtension() ) !== 'php' ) {
|
|
continue;
|
|
}
|
|
$c = file_get_contents( $f->getPathname() );
|
|
if ( false === $c ) {
|
|
continue;
|
|
}
|
|
|
|
preg_match_all(
|
|
'/(?:__|esc_html__|esc_attr__|esc_html_e|esc_attr_e|_e)\(\s*((?:\'(?:\\\\.|[^\'])*\')|(?:"(?:\\\\.|[^"])*"))\s*,\s*[\'\"]hesabix2[\'\"]/su',
|
|
$c,
|
|
$m
|
|
);
|
|
|
|
foreach ( $m[1] as $quoted ) {
|
|
$inner = stripslashes( substr( $quoted, 1, -1 ) );
|
|
$msgs[ $inner ] = true;
|
|
}
|
|
}
|
|
|
|
uksort(
|
|
$msgs,
|
|
static function ( $a, $b ) {
|
|
return strcmp( $a, $b );
|
|
}
|
|
);
|
|
|
|
$date = gmdate( 'Y-m-d H:i' ) . '+0000';
|
|
$hdr = <<<POT
|
|
msgid ""
|
|
msgstr ""
|
|
"Project-Id-Version: Hesabix2\\n"
|
|
"POT-Creation-Date: {$date}\\n"
|
|
"MIME-Version: 1.0\\n"
|
|
"Content-Type: text/plain; charset=UTF-8\\n"
|
|
"Content-Transfer-Encoding: 8bit\\n"
|
|
|
|
POT;
|
|
|
|
$out = $hdr;
|
|
|
|
foreach ( array_keys( $msgs ) as $msg ) {
|
|
if ( '' === $msg ) {
|
|
continue;
|
|
}
|
|
if ( str_contains( $msg, "\n" ) ) {
|
|
$lines = preg_split( '/\r\n|\r|\n/', $msg, -1, PREG_SPLIT_NO_EMPTY );
|
|
$out .= 'msgid ""' . "\n";
|
|
foreach ( $lines as $ln ) {
|
|
$safe = '"' . hesabix2_pot_escape_line( addcslashes( $ln, '\"' ) ) . '"' . "\n";
|
|
$out .= $safe;
|
|
}
|
|
$out .= 'msgstr ""' . "\n\n";
|
|
} else {
|
|
$safe = addcslashes( $msg, "\\\"\n\r\t" );
|
|
$out .= 'msgid "' . $safe . '"' . "\n";
|
|
$out .= 'msgstr ""' . "\n\n";
|
|
}
|
|
}
|
|
|
|
$file = dirname( __FILE__ ) . '/hesabix2.pot';
|
|
file_put_contents( $file, $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
|
|
echo basename( $file ) . ': ' . count( $msgs ) . " msgids.\n";
|