Project:
MantisBT
Code Location:
git://github.com/mantisbt/mantisbt-tools.gitmaster
/
Outline
- > Fn grab_lang_files()
- > Fn print_usage()
check_apostrophe.php
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
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
<?php /* This script does the following: - Checks for unescaped single quotes in the middle of strings. User must edit by hand. */ # -- GLOBAL VARIABLES -- $lang_files = array(); $english_strings = array(); # - --- # read in all language files function grab_lang_files() { global $lang_files; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if (strpos($file,'.txt')>0) { $lang_files[] = $file; } } closedir($handle); } } # - --- function found( $p_haystack, $p_needle ) { if ( strpos( $p_haystack, $p_needle ) > 0 ) { return true; } else { return false; } } # - --- function check_apostrophes( $p_file ) { $strings = file( $p_file ); $lang_strings = array(); $counter = 0; foreach( $strings as $string ) { $counter++; $string = trim( $string ); $apostrophe_count = substr_count( $string, "'" ); $apostrophe_escaped_count = substr_count( $string, "\'" ); $diff = $apostrophe_count - $apostrophe_escaped_count; if ( ( $diff ) > 2 ) { echo "$counter: $diff\n"; } } } # - --- function print_usage() { echo "\nUsage:\n php -q check_apostrophe.php <lang file>\n"; } # - --- # -- MAIN -- $argv = $_SERVER['argv']; $argc = $_SERVER['argc']; # too few arguments? if ( $argc < 2 ) { print_usage(); exit; } else if ( is_dir( $argv[1] ) ) { print_usage(); exit; } echo "Processing: ".$argv[1]."\n"; check_apostrophes( $argv[1] ); ?>
