forked from cilogon/service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgettext_po_to_mo.php
More file actions
54 lines (44 loc) · 1.54 KB
/
gettext_po_to_mo.php
File metadata and controls
54 lines (44 loc) · 1.54 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
52
53
54
<?php
/***
* This script scans for all .po (human-readable) translation files which were
* generated by the gettext_php_to_po.php script and creates corresponding
* .mo (machine-readable) translation files for use by gettext().
*/
// Ensure that this script runs only from the command line
if (strlen($_SERVER['DOCUMENT_ROOT']) > 0) {
exit;
}
// Run this script only from the script directory
if (__DIR__ != getcwd()) {
echo 'Please run this script from the ' . __DIR__ . ' directory.' . "\n";
exit;
}
// Run 'composer update' to pull in any library dependencies
$output = null;
if (
(exec('composer -V', $output, $result_code) === false) ||
($result_code != 0)
) {
echo "Unable to find 'composer' command.\n";
echo "Please see https://getcomposer.org/doc/00-intro.md for installation.\n";
exit;
}
exec('composer update');
// Setup done! Now run the actual program to generate the translation files
require_once __DIR__ . '/vendor/autoload.php';
use Gettext\Loader\PoLoader;
use Gettext\Generator\MoGenerator;
// Scan for all .po files and generate machine-readable .mo files
foreach (glob('./{*,*/*,*/*/*,*/*/*/*,*/*/*/*/*,*/*/*/*/*/*}.po', GLOB_BRACE) as $file) {
// Skip vendor libraries
if (preg_match('%\./vendor/%', $file)) {
continue;
}
echo "Processing $file\n";
$loader = new PoLoader();
$translations = $loader->loadFile($file);
$moGenerator = new MoGenerator();
$moFile = preg_replace('/\.po$/', '.mo', $file);
$moGenerator->generateFile($translations, $moFile);
}
echo "Done!\n";