set-domain
1.1 KB
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
#!/usr/bin/env php
<?php declare(strict_types=1);
function ask( string $question, string $default = '' ): string {
$answer = readline( $question . ( $default ? " ($default)" : null ) . ': ' );
if ( ! $answer ) {
return $default;
}
return $answer;
}
function replace_in_file( string $file, array $replacements ) {
$contents = file_get_contents( $file );
file_put_contents(
$file,
str_replace(
array_keys( $replacements ),
array_values( $replacements ),
$contents
)
);
}
function writeln( string $line ) {
echo $line . PHP_EOL;
}
function run( string $command ): string {
return trim( shell_exec( $command ) ?: '' );
}
parse_str( implode( '&', array_slice( $argv, 1 ) ), $result );
$domain = $result['domain'] ?? ask( 'Domain Name', 'stellar-uplink' );
if ( empty( $domain ) ) {
writeln( 'Translation domain could not be empty' );
exit( 0 );
}
$files = explode( PHP_EOL, run( 'grep -E -r -l -i "%TEXTDOMAIN%" \'' . dirname( __FILE__, 2 ) . '/src\'' ) );
$files = array_filter( $files );
foreach ( $files as $file ) {
replace_in_file( $file, [
'%TEXTDOMAIN%' => $domain
] );
}