Skip to content

Commit 04c86e4

Browse files
committed
Remove special rule for help_ files
# Conflicts: # src/Phpbb/TranslationValidator/Validator/FileValidator.php
1 parent 6ce4273 commit 04c86e4

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

src/Phpbb/TranslationValidator/Validator/FileValidator.php

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,13 @@ public function validate($sourceFile, $originFile)
248248
{
249249
$this->validateEmail($sourceFile, $originFile);
250250
}
251-
else if (strpos($originFile, $this->originLanguagePath . 'help_') === 0 && substr($originFile, -4) === '.php')
251+
else if ($originFile == $this->originLanguagePath . 'search_synonyms.php')
252252
{
253-
$this->validateHelpFile($sourceFile, $originFile);
253+
$this->validateSearchSynonymsFile($originFile);
254+
}
255+
else if ($originFile == $this->originLanguagePath . 'search_ignore_words.php')
256+
{
257+
$this->validateSearchIgnoreWordsFile($originFile);
254258
}
255259
else if (substr($originFile, -4) === '.php')
256260
{
@@ -488,96 +492,91 @@ public function validateEmail($sourceFile, $originFile)
488492
}
489493

490494
/**
491-
* Validates a help_*.php file
492-
*
493-
* Files must only contain the variable $help.
494-
* This variable must be an array of arrays.
495-
* Subarrays must only have the indexes 0 and 1,
496-
* with 0 being the headline and 1 being the description.
495+
* Validates the search_synonyms.php file
497496
*
498-
* Files must contain an entry with 0 and 1 being '--',
499-
* causing the column break in the page.
497+
* Files must only contain the variable $synonyms.
498+
* This variable must be an array of string => string entries.
500499
*
501500
* @todo Check for template vars and html
502-
* @todo Check for triple --- and other typos of it.
503501
*
504-
* @param string $sourceFile Source file for comparison
505502
* @param string $originFile File to validate
506503
* @return null
507504
*/
508-
public function validateHelpFile($sourceFile, $originFile)
505+
public function validateSearchSynonymsFile($originFile)
509506
{
510507
$originFilePath = $this->originPath . '/' . $originFile;
511-
$sourceFilePath = $this->sourcePath . '/' . $sourceFile;
512508

513509
if (!$this->safeMode)
514510
{
515-
/** @var $help */
511+
/** @var $synonyms */
516512
include($originFilePath);
517513

518514
$defined_variables = get_defined_vars();
519-
if (sizeof($defined_variables) != 5 || !isset($defined_variables['help']) || gettype($defined_variables['help']) != 'array')
515+
if (sizeof($defined_variables) != 3 || !isset($defined_variables['synonyms']) || gettype($defined_variables['synonyms']) != 'array')
520516
{
521-
$this->output->addMessage(Output::FATAL, 'Should only contain the help-array', $originFile);
517+
$this->output->addMessage(Output::FATAL, 'Must only contain the synonyms-array', $originFile);
522518
return;
523519
}
524520
}
525521

526522
else
527523
{
528-
/** @var $help */
529-
$help = ValidatorRunner::langParser($originFilePath);
530-
$this->output->addMessage(Output::NOTICE, '<bg=yellow;options=bold>[Safe Mode]</> Manually run the translation validator to check help variables.', $originFile);
531-
}
532-
533-
$validate = $help;
534-
unset($help);
535-
536-
if (!$this->safeMode)
537-
{
538-
/** @var $help */
539-
include($sourceFilePath);
524+
/** @var $synonyms */
525+
$synonyms = ValidatorRunner::langParser($originFilePath);
526+
$this->output->addMessage(Output::NOTICE, '<bg=yellow;options=bold>[Safe Mode]</> Manually run the translation validator to check synonym variables.', $originFile);
540527
}
541528

542-
else
529+
foreach ($synonyms as $synonym1 => $synonym2)
543530
{
544-
/** @var $help */
545-
$help = ValidatorRunner::langParser($sourceFilePath);
531+
if (gettype($synonym1) != 'string' || gettype($synonym2) != 'string')
532+
{
533+
$this->output->addMessage(Output::FATAL, 'Must only contain entries of type string => string: ' . serialize($synonym1) . ' => ' . serialize($synonym2), $originFile);
534+
}
546535
}
536+
}
547537

548-
$against = $help;
549-
unset($help);
538+
/**
539+
* Validates the search_ignore_words.php file
540+
*
541+
* Files must only contain the variable $words.
542+
* This variable must be an array of string entries.
543+
*
544+
* @todo Check for template vars and html
545+
*
546+
* @param string $originFile File to validate
547+
* @return null
548+
*/
549+
public function validateSearchIgnoreWordsFile($originFile)
550+
{
551+
$originFilePath = $this->originPath . '/' . $originFile;
550552

551-
$column_breaks = 0;
552-
$entry = 0;
553-
foreach ($validate as $help)
553+
if (!$this->safeMode)
554554
{
555-
if (gettype($help) != 'array' || sizeof($help) != 2 || !isset($help[0]) || !isset($help[1]))
556-
{
557-
$this->output->addMessage(Output::FATAL, 'Found invalid entry: ' . serialize($help), $originFile, $entry);
558-
}
559-
else if ($help[0] == '--' && $help[1] == '--')
560-
{
561-
$column_breaks++;
562-
}
555+
/** @var $words */
556+
include($originFilePath);
563557

564-
if (isset($help[0]))
558+
$defined_variables = get_defined_vars();
559+
if (sizeof($defined_variables) != 3 || !isset($defined_variables['words']) || gettype($defined_variables['words']) != 'array')
565560
{
566-
$compare = isset($against[$entry][0]) ? $against[$entry][0] : '';
567-
$this->langKeyValidator->validate($originFile, $entry . '.0', $compare, $help[0]);
561+
$this->output->addMessage(Output::FATAL, 'Must only contain the words-array', $originFile);
562+
return;
568563
}
564+
}
569565

570-
if (isset($help[1]))
571-
{
572-
$compare = isset($against[$entry][1]) ? $against[$entry][1] : '';
573-
$this->langKeyValidator->validate($originFile, $entry . '.1', $compare, $help[1]);
574-
}
575-
$entry++;
566+
else
567+
{
568+
/** @var $words */
569+
$words = ValidatorRunner::langParser($originFilePath);
570+
$this->output->addMessage(Output::NOTICE, '<bg=yellow;options=bold>[Safe Mode]</> Manually run the translation validator to check word variables.', $originFile);
576571
}
577572

578-
if ($column_breaks != 1)
573+
foreach ($words as $word)
579574
{
580-
$this->output->addMessage(Output::FATAL, 'Must have exactly one column break entry', $originFile);
575+
if (gettype($word) != 'string')
576+
{
577+
//@todo use $i
578+
$this->output->addMessage(Output::FATAL, 'Must only contain entries of type string: ' . serialize($word), $originFile);
579+
}
581580
}
582581
}
583582

0 commit comments

Comments
 (0)