summaryrefslogtreecommitdiffstats
path: root/app/l10n/extract.php
diff options
context:
space:
mode:
authorRomain d'Alverny <rdalverny@gmail.com>2022-01-11 12:36:17 +0100
committerRomain d'Alverny <rdalverny@gmail.com>2022-01-11 12:36:17 +0100
commit138865bbde25bb6193930c98e30c33913d19e367 (patch)
tree626e8e26dd4f4776ce9f8cd743987f08377127ed /app/l10n/extract.php
parent5f2b708377aec4bc5f1d731dfbb50557552d0482 (diff)
downloadplanet-138865bbde25bb6193930c98e30c33913d19e367.tar
planet-138865bbde25bb6193930c98e30c33913d19e367.tar.gz
planet-138865bbde25bb6193930c98e30c33913d19e367.tar.bz2
planet-138865bbde25bb6193930c98e30c33913d19e367.tar.xz
planet-138865bbde25bb6193930c98e30c33913d19e367.zip
Install code QA helpers, enforce PSR2
Installs phpcs, phpmd, parallel-lint, phpstan.
Diffstat (limited to 'app/l10n/extract.php')
-rwxr-xr-xapp/l10n/extract.php78
1 files changed, 41 insertions, 37 deletions
diff --git a/app/l10n/extract.php b/app/l10n/extract.php
index 1384827..ef44912 100755
--- a/app/l10n/extract.php
+++ b/app/l10n/extract.php
@@ -29,41 +29,44 @@ $GLOBALS['english'] = array();
*
*/
-function extract_l10n_strings($file) {
+function extract_l10n_strings($file)
+{
$lines = file($file);
$patterns = array('/_g\([\'"](.*?)[\'"]\)/', '/getString\([\'"](.*?)[\'"]\)/',);
foreach ($lines as $line) {
-
// Skip comments
- if($line[0] == '#' || $line[0] == '/') continue;
+ if ($line[0] == '#' || $line[0] == '/') {
+ continue;
+ }
// parsing logic
- foreach($patterns as $pattern) {
- if(preg_match_all($pattern, $line, $matches, PREG_PATTERN_ORDER)) {
- foreach($matches[1] as $val) {
-
+ foreach ($patterns as $pattern) {
+ if (preg_match_all($pattern, $line, $matches, PREG_PATTERN_ORDER)) {
+ foreach ($matches[1] as $val) {
// Do not extract php variables calls or empty strings
- if($val[0] == '$' || $val == '') continue;
+ if ($val[0] == '$' || $val == '') {
+ continue;
+ }
// Is there a localization comment ?
$l10n_note = explode("',", $val);
// Also test strings in double quotes
- if(count($l10n_note) == 1) {
+ if (count($l10n_note) == 1) {
$l10n_note = explode('",', $val);
}
// Extract cleaned up strings
- if(count($l10n_note) == 2) {
+ if (count($l10n_note) == 2) {
$l10n_str = trim($l10n_note[0]);
- $l10n_note = trim(substr(trim($l10n_note[1]),1)); # Remove quote at begining of string
+ $l10n_note = trim(substr(trim($l10n_note[1]), 1)); # Remove quote at begining of string
} else {
$l10n_str = trim($val);
$l10n_note = '';
}
- if(!array_key_exists($l10n_str, $GLOBALS['english'])) {
+ if (!array_key_exists($l10n_str, $GLOBALS['english'])) {
$GLOBALS['english'][$l10n_str] = array($l10n_str, $l10n_note);
}
}
@@ -80,12 +83,13 @@ function extract_l10n_strings($file) {
* show_l10n_strings() ;
*/
-function show_l10n_strings() {
+function show_l10n_strings()
+{
header('Content-Type:text/plain');
- foreach($GLOBALS['english'] as $val) {
- if($val[1]) {
+ foreach ($GLOBALS['english'] as $val) {
+ if ($val[1]) {
echo '# ' . $val[1] . "\n";
}
echo ";$val[0]\n";
@@ -98,28 +102,28 @@ function show_l10n_strings() {
* returns an array of file paths
*/
-function find_all_files($dir) {
+function find_all_files($dir)
+{
$result = array();
$root = scandir($dir);
$ignore = array('.', '..', '.git', '.svn', '.hg', 'cache', '.gitignore', 'lib');
- foreach($root as $value) {
-
- if(in_array($value, $ignore)) {
+ foreach ($root as $value) {
+ if (in_array($value, $ignore)) {
continue;
}
- if(is_file("$dir/$value")) {
+ if (is_file("$dir/$value")) {
$split = explode('.', $value);
- if(end($split) == 'php'){
+ if (end($split) == 'php') {
$result[] = "$dir/$value";
}
continue;
}
- foreach(find_all_files("$dir/$value") as $value) {
+ foreach (find_all_files("$dir/$value") as $value) {
$result[]=$value;
}
}
@@ -127,11 +131,12 @@ function find_all_files($dir) {
return $result;
}
-function update_lang_files($source, $dest) {
+function update_lang_files($source, $dest)
+{
$files = find_all_files($source);
- foreach($files as $file) {
+ foreach ($files as $file) {
extract_l10n_strings($file);
}
@@ -142,39 +147,38 @@ function update_lang_files($source, $dest) {
// list locales
$locales = array();
- foreach($files as $file) {
-
- if(in_array($file, $ignore)) {
+ foreach ($files as $file) {
+ if (in_array($file, $ignore)) {
continue;
}
$split = explode('.', $file);
- if($split[1] == 'lang') {
+ if ($split[1] == 'lang') {
$locales[] = $split[0];
}
- }
+ }
- foreach($locales as $locale) {
+ foreach ($locales as $locale) {
$status[$locale] = 0;
$lang_file_path = $dest . '/' . $locale;
Simplel10n::load($lang_file_path);
ob_start();
- foreach($GLOBALS['english'] as $key => $val) {
+ foreach ($GLOBALS['english'] as $key => $val) {
$warning = '';
$value = @Simplel10n::extractString($key);
- if($value == $val[0]) {
+ if ($value == $val[0]) {
$status[$locale]++;
$warning = ' ** String needs translation **';
}
- if($val[1]) {
+ if ($val[1]) {
echo '# Translation note: ' . $val[1] . $warning . "\n";
- } elseif($warning != '') {
+ } elseif ($warning != '') {
echo '# Translation note: ' . $warning . "\n";
}
@@ -187,16 +191,16 @@ function update_lang_files($source, $dest) {
file_put_contents($lang_file_path. '.lang', $content);
unset($GLOBALS['locale']);
- }
+ }
// Display a short status report
header('Content-Type:text/plain');
echo "Number of English strings: " . count($GLOBALS['english']) . "\n";
echo "Your installation has these languages installed: " . implode(', ', $locales) . "\n";
- foreach($locales as $val) {
+ foreach ($locales as $val) {
echo $val . " has " . $status[$val] . " untranslated strings.\n";
- }
+ }
}
update_lang_files($root, $root . 'app/l10n');