Xinax\LaravelGettext\Config\Models\Config::getSourcesFromDomain PHP Method

getSourcesFromDomain() public method

Return all routes for a single domain
public getSourcesFromDomain ( $domain ) : array
$domain
return array
    public function getSourcesFromDomain($domain)
    {
        // grab any paths wrapped in $domain
        $explicitPaths = array_key_exists($domain, $this->sourcePaths) ? $this->sourcePaths[$domain] : [];
        // if we're not including the default domain, return what we have so far
        if ($this->domain != $domain) {
            return $explicitPaths;
        }
        // otherwise, grab all the default domain paths
        // and merge them with paths wrapped in $domain
        return array_reduce($this->sourcePaths, function ($carry, $path) {
            if (!is_array($path)) {
                $carry[] = $path;
            }
            return $carry;
        }, $explicitPaths);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Creates a configured .po file on $path. If write is true the file will
  * be created, otherwise the file contents are returned.
  *
  * @param  String  $path
  * @param  String  $locale
  * @param  String  $domain
  * @param  Boolean $write
  * @return Integer | String
  */
 public function createPOFile($path, $locale, $domain, $write = true)
 {
     $project = $this->configuration->getProject();
     $timestamp = date("Y-m-d H:iO");
     $translator = $this->configuration->getTranslator();
     $encoding = $this->configuration->getEncoding();
     // L5 new structure, language resources are now here
     $relativePath = "../../../../../app";
     $template = 'msgid ""' . "\n";
     $template .= 'msgstr ""' . "\n";
     $template .= '"Project-Id-Version: ' . $project . '\\n' . "\"\n";
     $template .= '"POT-Creation-Date: ' . $timestamp . '\\n' . "\"\n";
     $template .= '"PO-Revision-Date: ' . $timestamp . '\\n' . "\"\n";
     $template .= '"Last-Translator: ' . $translator . '\\n' . "\"\n";
     $template .= '"Language-Team: ' . $translator . '\\n' . "\"\n";
     $template .= '"Language: ' . $locale . '\\n' . "\"\n";
     $template .= '"MIME-Version: 1.0' . '\\n' . "\"\n";
     $template .= '"Content-Type: text/plain; charset=' . $encoding . '\\n' . "\"\n";
     $template .= '"Content-Transfer-Encoding: 8bit' . '\\n' . "\"\n";
     $template .= '"X-Generator: Poedit 1.5.4' . '\\n' . "\"\n";
     $template .= '"X-Poedit-KeywordsList: _' . '\\n' . "\"\n";
     $template .= '"X-Poedit-Basepath: ' . $relativePath . '\\n' . "\"\n";
     $template .= '"X-Poedit-SourceCharset: ' . $encoding . '\\n' . "\"\n";
     // Source paths
     $sourcePaths = $this->configuration->getSourcesFromDomain($domain);
     // Compiled views on paths
     if (count($sourcePaths)) {
         // View compilation
         $this->compileViews($sourcePaths, $domain);
         array_push($sourcePaths, $this->getStorageForDomain($domain));
         $i = 0;
         foreach ($sourcePaths as $sourcePath) {
             $template .= '"X-Poedit-SearchPath-' . $i . ': ' . $sourcePath . '\\n' . "\"\n";
             $i++;
         }
     }
     if ($write) {
         // File creation
         $file = fopen($path, "w");
         $result = fwrite($file, $template);
         fclose($file);
         return $result;
     } else {
         // Contents for update
         return $template . "\n";
     }
 }