Themsaid\Langman\Manager::getKeysExistingInALanguageButNotTheOther PHP Method

getKeysExistingInALanguageButNotTheOther() public method

Given a dot array of all keys in the format 'file.language.key', this method searches for keys that exist in one language but not the other and outputs an array consists of those keys.
public getKeysExistingInALanguageButNotTheOther ( $values ) : array
$values
return array
    public function getKeysExistingInALanguageButNotTheOther($values)
    {
        $missing = [];
        // Array of keys indexed by fileName.key, those are the keys we looked
        // at before so we save them in order for us to not look at them
        // again in a different language iteration.
        $searched = [];
        // Now we add keys that exist in a language but missing in any of the
        // other languages. Those keys combined with ones with values = ''
        // will be sent to the console user to fill and save in disk.
        foreach ($values as $key => $value) {
            list($fileName, $languageKey, $key) = explode('.', $key, 3);
            if (in_array("{$fileName}.{$key}", $searched)) {
                continue;
            }
            foreach ($this->languages() as $languageName) {
                if (!Arr::has($values, "{$fileName}.{$languageName}.{$key}") && !array_key_exists("{$fileName}.{$languageName}.{$key}", $values)) {
                    $missing[] = "{$fileName}.{$key}:{$languageName}";
                }
            }
            $searched[] = "{$fileName}.{$key}";
        }
        return $missing;
    }

Usage Example

 /**
  * Get an array of keys that have missing values with a hint
  * from another language translation file if possible.
  *
  * ex: [ ['key' => 'product.color.nl', 'hint' => 'en = "color"'] ]
  *
  * @param array $languages
  * @return array
  */
 private function getMissing(array $languages)
 {
     $files = $this->manager->files();
     // Array of content of all files indexed by fileName.languageKey
     $filesResults = [];
     // The final output of the method
     $missing = [];
     // Here we collect the file results
     foreach ($files as $fileName => $languageFiles) {
         foreach ($languageFiles as $languageKey => $filePath) {
             $filesResults[$fileName][$languageKey] = $this->manager->getFileContent($filePath);
         }
     }
     $values = Arr::dot($filesResults);
     $emptyValues = array_filter($values, function ($value) {
         return $value == '';
     });
     // Adding all keys that has values = ''
     foreach ($emptyValues as $dottedValue => $emptyValue) {
         list($fileName, $languageKey, $key) = explode('.', $dottedValue, 3);
         $missing[] = "{$fileName}.{$key}:{$languageKey}";
     }
     $missing = array_merge($missing, $this->manager->getKeysExistingInALanguageButNotTheOther($values));
     return $missing;
 }
All Usage Examples Of Themsaid\Langman\Manager::getKeysExistingInALanguageButNotTheOther