aboutsummaryrefslogtreecommitdiffstats
path: root/util/extract.php
blob: bc838c7129bd0733e1bc73783315f6ede428e398 (plain) (blame)
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
<?php

	$arr = array();

	$files = array('index.php','boot.php');
	$files = array_merge($files,glob('mod/*'),glob('include/*'),glob('addon/*/*'));


	foreach($files as $file) {
		$str = file_get_contents($file);

		$pat = '| t\(([^\)]*)\)|';
		$patt = '| tt\(([^\)]*)\)|';

		preg_match_all($pat,$str,$matches);
		preg_match_all($patt, $str, $matchestt);
		

		if(count($matches)){
			foreach($matches[1] as $match) {
				if(! in_array($match,$arr))
					$arr[] = $match;
			}
		}
		if(count($matchestt)){
			foreach($matchestt[1] as $match) {
				$matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|",$match);
				if (count($matchtkns)==3 && !in_array($matchtkns,$arr)){
					$arr[] = $matchtkns;
				}
			}
		}

	}

	$s = '<?php' . "\n";
	$s .= '
function string_plural_select($n){
	return ($n != 1);
}

';

	foreach($arr as $a) {
		if (is_array($a)){
			if(substr($a[1],0,1) == '$')
				continue;
			$s .= 'App::$strings[' . $a[0] . "] = array(\n";
			$s .= "\t0 => ". $a[0]. ",\n";
			$s .= "\t1 => ". $a[1]. ",\n";
			$s .= ");\n";
		} else {
			if(substr($a,0,1) == '$')
				continue;			
			$s .= 'App::$strings[' . $a . '] = '. $a . ';' . "\n";
		}
	}

	$zones = timezone_identifiers_list();
	foreach($zones as $zone)
		$s .= 'App::$strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";
	
	echo $s;