Vsch\TranslationManager\Manager::missingKey PHP Method

missingKey() public method

public missingKey ( $namespace, $group, $key, null $locale = null, boolean $useLottery = false, boolean $findOrNew = false ) : Translation | null
$namespace string
$group string
$key string
$locale null
$useLottery boolean
$findOrNew boolean
return Vsch\TranslationManager\Models\Translation | null
    public function missingKey($namespace, $group, $key, $locale = null, $useLottery = false, $findOrNew = false)
    {
        if (!$useLottery || $this->config(self::LOG_MISSING_KEYS_KEY)) {
            // Fucking L5 changes
            $group = self::fixGroup($group);
            $group = $namespace && $namespace !== '*' ? $namespace . '::' . $group : $group;
            if (!in_array($group, $this->config(self::EXCLUDE_GROUPS_KEY))) {
                $lottery = 1;
                if ($useLottery && $this->config(self::MISSING_KEYS_LOTTERY_KEY) !== 1) {
                    $lottery = \Session::get($this->config(self::PERSISTENT_PREFIX_KEY) . self::LOTTERY_PERSISTENT_SUFFIX, '');
                    if ($lottery === '') {
                        $lottery = rand(1, $this->config(self::MISSING_KEYS_LOTTERY_KEY));
                        \Session::put($this->config(self::PERSISTENT_PREFIX_KEY) . self::LOTTERY_PERSISTENT_SUFFIX, $lottery);
                    }
                }
                if ($lottery === 1) {
                    // here need to map a local group to wbn: or vnd: package if the local file does not already exist so that
                    // new keys will be added to the appropriate package
                    $augmentedGroupList = $this->getGroupAugmentedList();
                    if (array_key_exists($group, $augmentedGroupList)) {
                        $group = $augmentedGroupList[$group];
                    }
                    $locale = $locale ?: $this->app['config']['app.locale'];
                    if ($findOrNew) {
                        $translation = $this->firstOrNewTranslation(array('locale' => $locale, 'group' => $group, 'key' => $key));
                    } else {
                        $translation = $this->firstOrCreateTranslation(array('locale' => $locale, 'group' => $group, 'key' => $key));
                    }
                    return $translation;
                }
            }
        }
        return null;
    }

Usage Example

 public function postAdd($group)
 {
     $keys = explode("\n", trim(\Request::get('keys')));
     $suffixes = explode("\n", trim(\Request::get('suffixes')));
     $group = explode('::', $group, 2);
     $namespace = '*';
     if (count($group) > 1) {
         $namespace = array_shift($group);
     }
     $group = $group[0];
     foreach ($keys as $key) {
         $key = trim($key);
         if ($group && $key) {
             if ($suffixes) {
                 foreach ($suffixes as $suffix) {
                     $this->manager->missingKey($namespace, $group, $key . trim($suffix));
                 }
             } else {
                 $this->manager->missingKey($namespace, $group, $key);
             }
         }
     }
     //Session::flash('_old_data', \Request::except('keys'));
     return \Redirect::back()->withInput();
 }