Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions tools/linst2pot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

/**
* Script that generates a LINST instrument's pot (PO template) file for
* translation. This should make it easier to send translations to translators
*/

// require_once __DIR__ . "/generic_includes.php";

$stdin = fopen("php://stdin", "r");
$seenStrings = [];
$createdAt = new \DateTimeImmutable()->format("Y-m-d H:iO");
print <<<EOH
# Autogenerated default strings to be translated for LORIS instrument

msgid ""
msgstr ""
"Project-Id-Version: LORIS 27\\n"
"Report-Msgid-Bugs-to: https://github.com/aces/Loris/issues\\n"
"POT-Creation-Date: $createdAt\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <LI@li.org\\n"
"Language: \\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"


EOH;

function addMsg(string $label) {
global $seenStrings;
if(!empty($label) && !isset($seenStrings[$label])) {
print "msgid \"$label\"\n";
print "msgstr \"\"\n\n";
$seenStrings[$label] = true;
}
}

while (($line = fgets($stdin)) !== false)
{
$pieces = explode('{@}', $line);
$label = trim($pieces[2] ?? '');
if ($label !== null && $label !== '') {
addMsg($label);
}
if(!empty(trim($pieces[3] ?? ''))) {
$options = explode('{-}', $pieces[3]);
foreach($options as $option) {
$values = [];
if(preg_match("/'(.+)'=>'(.+)'/", $option, $values) === 1) {
addMsg($values[2]);
}
}
}
}
fclose($stdin);
56 changes: 27 additions & 29 deletions tools/lorisform_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/generic_includes.php";

$opts = getopt("", ["stdout::"]);
$stdout = isset($opts['stdout']);

$instrumentsToSkip = [];
$instruments = getExcludedInstruments();
foreach ($instruments as $instrument) {
Expand All @@ -31,7 +34,7 @@
while ($file=fgets(STDIN)) {
$file =trim($file);
$files[] =$file;
echo $file;
fwrite(STDERR, $file);
}

//Process the files
Expand All @@ -42,42 +45,33 @@
fclose($fp);
preg_match("/class (.+) extends NDB_BVL_Instrument/", $data, $matches);
if (empty($matches[1])) {
echo "File '$file' does not contain an instrument.\n";
fwrite(STDERR, "File '$file' does not contain an instrument.\n");
continue;
}
echo "Reading file $file\n";
fwrite(STDERR, "Reading file $file\n");
$className =$matches[1];
echo "Instrument found: $matches[1]\n";
echo "Requiring file...\n";
include_once $file;
echo "Instantiating new object...\n";
$obj =new $className(
$lorisInstance,
new NullModule($lorisInstance),
"",
"",
"",
""
);
echo "Initializing instrument object...\n";
$obj->setup(null, null);
fwrite(STDERR, "Instrument found: $matches[1]\n");
fwrite(STDERR, "Instantiating new object...\n");

$testname = preg_replace("/NDB_BVL_Instrument_/", "", $className);
$obj = \NDB_BVL_Instrument::factory($lorisInstance, $testname);

//Some instruments ought not be parsed with the lorisform_parser
if ((in_array($obj->testName, $instrumentsToSkip))) {
echo "lorisform_parser will skip file {$file}\n";
fwrite(STDERR, "lorisform_parser will skip file {$file}\n");
continue;
}

$subtests =$obj->getSubtestList();
foreach ($subtests as $subtest) {
$obj->page =$subtest['Name'];
echo "Building instrument page '$subtest[Name]'...\n";
fwrite(STDERR, "Building instrument page '$subtest[Name]'...\n");
$obj->_setupForm();
}

if (is_array($obj->getFullName())) {
echo "Could not find row for $matches[1] in table test_names,
please populate test_names, instrument_subtests\n";
fwrite(STDERR, "Could not find row for $matches[1] in table test_names,
please populate test_names, instrument_subtests\n");
continue;
}

Expand All @@ -87,7 +81,7 @@
$output = '';
}

echo "Parsing instrument object...\n";
fwrite(STDERR, "Parsing instrument object...\n");

$output .="testname{@}".$obj->testName."\n";
$output .="table{@}".$obj->table."\n";
Expand All @@ -96,14 +90,18 @@

$formElements = $obj->form->toElementArray();
$output .=parseElements($formElements["elements"]);
echo "Parsing complete\n---------------------------------------------------\n\n";
fwrite(STDERR, "Parsing complete\n---------------------------------------------------\n\n");
}
if (empty($output)) {
echo "Nothing to output, 'ip_output.txt' not created\n";
fwrite(STDERR, "Nothing to output, 'ip_output.txt' not created\n");
} else {
$fp =fopen("ip_output.txt", "w");
fwrite($fp, $output);
fclose($fp);
if($stdout) {
fwrite(STDOUT, $output);
} else {
$fp =fopen("ip_output.txt", "w");
fwrite($fp, $output);
fclose($fp);
}
}

/**
Expand Down Expand Up @@ -225,11 +223,11 @@ function parseElements($elements, $groupLabel = "")
case "file":
case "hidden":
// skip because it's useless
echo "SKIP: skipping quickform element type: ".$element['type']."\n";
fwrite(STDERR, "SKIP: skipping quickform element type: ".$element['type']."\n");
break;

default:
echo "WARNING: Unknown form element type: ".$element['type']."\n";
fwrite(STDERR, "WARNING: Unknown form element type: ".$element['type']."\n");
break;
}
}
Expand Down
Loading