Merge pull request #3254 from samsonasik/alternative-for-app-translation-validation-override-system

Fixes #3125 : add ability to override existing translation en in system language from App
This commit is contained in:
MGatner 2020-07-10 10:55:14 -04:00 committed by GitHub
commit fd70a90279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 5 deletions

View File

@ -0,0 +1,4 @@
<?php
// override core en language system validation or define your own en language validation message
return [];

View File

@ -226,25 +226,47 @@ class FileLocator
* 'app/Modules/bar/Config/Routes.php',
* ]
*
* @param string $path
* @param string $ext
* @param string $path
* @param string $ext
* @param boolean $prioritizeApp
*
* @return array
*/
public function search(string $path, string $ext = 'php'): array
public function search(string $path, string $ext = 'php', bool $prioritizeApp = true): array
{
$path = $this->ensureExt($path, $ext);
$foundPaths = [];
$appPaths = [];
foreach ($this->getNamespaces() as $namespace)
{
if (isset($namespace['path']) && is_file($namespace['path'] . $path))
{
$foundPaths[] = $namespace['path'] . $path;
$fullPath = $namespace['path'] . $path;
if ($prioritizeApp)
{
$foundPaths[] = $fullPath;
}
else
{
if (strpos($fullPath, APPPATH) === 0)
{
$appPaths[] = $fullPath;
}
else
{
$foundPaths[] = $fullPath;
}
}
}
}
if (! $prioritizeApp && ! empty($appPaths))
{
$foundPaths = array_merge($foundPaths, $appPaths);
}
// Remove any duplicates
$foundPaths = array_unique($foundPaths);

View File

@ -338,7 +338,7 @@ class Language
*/
protected function requireFile(string $path): array
{
$files = Services::locator()->search($path);
$files = Services::locator()->search($path, 'php', false);
$strings = [];
foreach ($files as $file)

View File

@ -191,6 +191,22 @@ class FileLocatorTest extends \CodeIgniter\Test\CIUnitTestCase
$this->assertArrayNotHasKey(0, $foundFiles);
}
//--------------------------------------------------------------------
public function testSearchPrioritizeSystemOverApp()
{
$foundFiles = $this->locator->search('Language/en/Validation.php', 'php', false);
$this->assertEquals([
SYSTEMPATH . 'Language/en/Validation.php',
APPPATH . 'Language/en/Validation.php',
],
$foundFiles
);
}
//--------------------------------------------------------------------
public function testListNamespaceFilesEmptyPrefixAndPath()
{
$this->assertEmpty($this->locator->listNamespaceFiles('', ''));