Xinax\LaravelGettext\FileSystem::updateLocale PHP Method

updateLocale() public method

Update the .po file headers by domain (mainly source-file paths)
public updateLocale ( $localePath, $locale, $domain ) : boolean
$localePath
$locale
$domain
return boolean
    public function updateLocale($localePath, $locale, $domain)
    {
        $data = [$localePath, "LC_MESSAGES", $domain . ".po"];
        if ($this->configuration->getCustomLocale()) {
            $customLocale = array('C');
            array_splice($data, 1, 0, $customLocale);
        }
        $localePOPath = implode($data, DIRECTORY_SEPARATOR);
        if (!file_exists($localePOPath) || !($localeContents = file_get_contents($localePOPath))) {
            throw new LocaleFileNotFoundException(sprintf('Can\'t read %s verify your locale structure', $localePOPath));
        }
        $newHeader = $this->createPOFile($localePOPath, $locale, $domain, false);
        // Header replacement
        $localeContents = preg_replace('/^([^#])+:?/', $newHeader, $localeContents);
        if (!file_put_contents($localePOPath, $localeContents)) {
            throw new LocaleFileNotFoundException(sprintf('Can\'t write on %s', $localePOPath));
        }
        return true;
    }

Usage Example

 /**
  * Test the update 
  */
 public function testFileSystem()
 {
     // Domain path test
     $domainPath = $this->fileSystem->getDomainPath();
     // Locale path test
     $locale = 'es_AR';
     $localePath = $this->fileSystem->getDomainPath($locale);
     // Create locale test
     $localesGenerated = $this->fileSystem->generateLocales();
     $this->assertTrue($this->fileSystem->checkDirectoryStructure(true));
     $this->assertCount(3, $localesGenerated);
     $this->assertTrue(is_dir($domainPath));
     $this->assertTrue(strpos($domainPath, 'i18n') !== false);
     foreach ($localesGenerated as $localeGenerated) {
         $this->assertTrue(file_exists($localeGenerated));
     }
     $this->assertTrue(is_dir($localePath));
     // Update locale test
     $this->assertTrue($this->fileSystem->updateLocale($localePath, $locale, "backend"));
 }