public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
helper-scripts/add-new-lang-keys.php
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
<?php
3
function array_diff_key_recursive (array $arr1, array $arr2) {
4
$diff = array_diff_key($arr1, $arr2);
5
$intersect = array_intersect_key($arr1, $arr2);
7
foreach ($intersect as $k => $v) {
8
if (is_array($arr1[$k]) && is_array($arr2[$k])) {
9
$d = array_diff_key_recursive($arr1[$k], $arr2[$k]);
11
if ($d) {
12
$diff[$k] = $d;
13
}
14
}
15
}
17
return $diff;
18
}
20
// target lang
21
$targetLang = $argv[1];
23
if(empty($targetLang)) {
24
die('Please specify target lang as the first argument, to which you want to add missing keys from master lang (EN). Use the lowercase name,
25
for example `sk` for the Slovak language'."\n");
26
}
28
// load master lang
29
$masterLang = file_get_contents(__DIR__.'/../data/web/lang/lang.en-gb.json');
30
$masterLang = json_decode($masterLang, true);
32
// load target lang
33
$lang = file_get_contents(__DIR__.'/../data/web/lang/lang.'.$targetLang.'.json');
34
$lang = json_decode($lang, true);
36
// compare lang keys
37
$result = array_diff_key_recursive($masterLang, $lang);
39
if(empty($result)) {
40
die('No new keys were added. Looks like target lang is up to date.'."\n");
41
}
43
foreach($result as $key => $val) {
44
// check if section key exists in target lang
45
if(array_key_exists($key, $lang)) {
46
// add only missing section keys
47
foreach ($val as $k => $v) {
48
$lang[$key][$k] = $v;
49
}
50
// sort keys
51
ksort($lang[$key]);
52
} else {
53
// add whole section
54
$lang[$key] = $val;
55
ksort($lang);
56
}
57
}
59
$lang = json_encode($lang, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
60
file_put_contents(__DIR__.'/../data/web/lang/lang.'.$targetLang.'.json', $lang);
62
echo 'Following new lang keys were added and need translation:'."\n";
63
print_r($result);