#!/usr/bin/php
<?php
/*
* OIDplus 2.0
* Copyright 2020 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Use this script to create files containing all strings of a specific language
// These files can be used for proofing (e.g. using Microsoft Word)
$dir = __DIR__ . '/../../';
// ---
$tmp = glob($dir.'/plugins/language/*/messages.xml');
foreach ($tmp as $tmp2) {
$lang = $tmp3[count($tmp3)-2];
if ($lang == 'enus') continue; // ignore base lang
$langs[] = $lang;
}
// ---
$it = new RecursiveDirectoryIterator($dir);
foreach(new RecursiveIteratorIterator($it) as $file) {
if ($file->getExtension() == 'php') {
$cont = str_replace('function _L($str, ...$sprintfArgs) {', '', $cont);
$strings = get_php_L_strings($cont);
}
if ($file->getExtension() == 'js') {
$strings = get_js_L_strings($cont);
}
}
echo "Done: enus\n";
// ---
foreach ($langs as $lang) {
$translation_file = $dir.'/plugins/language/'.$lang.'/messages.xml';
if (!$xml) {
echo "STOP: Cannot load $translation_file\n";
continue;
}
foreach ($xml->message as $msg) {
$dst = trim($msg->target->__toString
());
$all_strings[] = $dst;
}
}
echo "Done: $lang\n";
}
echo "All done!\n";
} else {
echo "Attention: No language plugins found!\n";
}
# ---
function get_js_L_strings($cont) {
// Works with JavaScript and PHP
preg_match_all('@[^_A-Za-z0-9]_L\\(.*(["\'])(.+)\\1@ismU', $cont, $m);
foreach ($m[2] as &$x) {
}
return $m[2];
}
function get_php_L_strings($cont) {
// Works only with PHP
$activated = 0;
foreach ($tokens as $token) {
if (($token[0] == T_STRING) && ($token[1] == '_L')) {
$activated = 1;
} else if (($activated == 1) && ($token[0] == T_CONSTANT_ENCAPSED_STRING)) {
$activated = 0;
}
}
}
return $out;
}