forked from textpattern/textpacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
textpack
executable file
·49 lines (38 loc) · 1.1 KB
/
textpack
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
#!/usr/bin/php
<?php
include __DIR__ . '/tests/Textpattern/Textpack/Test/Parser.php';
$template = file_get_contents(__DIR__ . '/textpacks/en-gb.textpack');
$files = (array) glob(__DIR__ . '/textpacks/*-*.textpack');
foreach ($files as $file)
{
if (!is_readable($file) || !is_file($file))
{
continue;
}
$out = array();
$merge = array();
if ($contents = file_get_contents($file))
{
$textpack = new Textpattern\Textpack\Test\Parser();
$textpack = $textpack->parse($contents);
foreach ($textpack as $data)
{
$merge[$data['name']] = $data['data'];
}
}
foreach (explode("\n", $template) as $line)
{
if (strpos($line, '#') !== 0)
{
$name = trim(join('', array_slice(explode('=>', $line), 0, 1)));
$line = $name.' => ';
if (isset($merge[$name]))
{
$line .= $merge[$name];
}
}
$out[] = trim($line);
}
file_put_contents($file, implode("\n", $out) . "\n");
}
echo "Iterated over ".count($files)." textpacks.\n";