mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
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:
commit
fd70a90279
4
app/Language/en/Validation.php
Normal file
4
app/Language/en/Validation.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// override core en language system validation or define your own en language validation message
|
||||
return [];
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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('', ''));
|
||||
|
Loading…
x
Reference in New Issue
Block a user