-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
80 lines (64 loc) · 2.56 KB
/
app.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
72
73
74
75
76
77
78
79
80
<?php
// Load FilesUtils class
require('files_utils.php');
// Set here the primary language
const PRIMARY_LANG = 'pt-br';
echo "===== Get all languages to be processed... =====<br><br>";
$langFiles = FilesUtils::getFiles('langs');
echo "Languages files loaded: <b>" . implode('</b>, <b>', $langFiles) . '</b><br><br>';
echo "===== Generating static files... =====<br><br>";
// Get all files to be processed
$filesPath = 'files';
$files = FilesUtils::getAllFiles($filesPath);
// Creates the output directory (or cleans it)
if (file_exists('output')) {
FilesUtils::deleteDir('output');
}
mkdir('output');
// Creates the languages directory
foreach ($langFiles as $langFile) {
$langFilename = FilesUtils::removeExtension($langFile);
$langDir = 'output/' . $langFilename;
if ($langFilename != PRIMARY_LANG) {
if (file_exists($langDir)) {
FilesUtils::deleteDir($langDir);
}
mkdir($langDir);
}
}
// For each file...
foreach($files as $file) {
$filename = FilesUtils::removeExtension($file);
$extension = FilesUtils::getExtension($file);
$targetExtension = $extension == "php" ? "html" : $extension;
echo "* Processing " . (is_file($filesPath . '/' . $file) ? "file" : "directory") . ": " . $file . "<br>";
// Generates it with each lang
foreach ($langFiles as $langFile) {
$langFilename = FilesUtils::removeExtension($langFile);
$langDir = 'output/' . $langFilename;
$langFinalPath = ($langFilename == PRIMARY_LANG ? 'output/' : $langDir . '/') . $filename . '.' . $targetExtension;
if (is_dir($filesPath . '/' . $file)) {
// If it is a directory, just creates it
$langFinalPath = ($langFilename == PRIMARY_LANG ? 'output/' : $langDir . '/') . $filename;
mkdir($langFinalPath);
echo " | Lang: " . $langFilename . ". Folder created<br>";
} else {
// Otherwise, do something with the file
$langFinalPath = ($langFilename == PRIMARY_LANG ? 'output/' : $langDir . '/') . $filename . '.' . $targetExtension;
if ($extension == "php") {
// If the file is php, then process it
echo " | Lang: " . $langFilename . "<br>";
include('langs/' . $langFile);
ob_start();
include($filesPath . '/' . $file);
file_put_contents($langFinalPath, ob_get_contents());
ob_end_clean();
} else {
// Otherwise, just copy it to the language folder
echo " | Lang: " . $langFilename . ". File copied<br>";
copy($filesPath . '/' . $file, $langFinalPath);
}
}
}
echo " | Done.<br><br>";
}