Barryvdh\TranslationManager\Manager::importTranslations PHP Method

importTranslations() public method

public importTranslations ( $replace = false )
    public function importTranslations($replace = false)
    {
        $counter = 0;
        foreach ($this->files->directories($this->app->langPath()) as $langPath) {
            $locale = basename($langPath);
            foreach ($this->files->allfiles($langPath) as $file) {
                $info = pathinfo($file);
                $group = $info['filename'];
                if (in_array($group, $this->config['exclude_groups'])) {
                    continue;
                }
                $subLangPath = str_replace($langPath . DIRECTORY_SEPARATOR, "", $info['dirname']);
                if ($subLangPath != $langPath) {
                    $group = $subLangPath . "/" . $group;
                }
                $translations = \Lang::getLoader()->load($locale, $group);
                if ($translations && is_array($translations)) {
                    foreach (array_dot($translations) as $key => $value) {
                        // process only string values
                        if (is_array($value)) {
                            continue;
                        }
                        $value = (string) $value;
                        $translation = Translation::firstOrNew(array('locale' => $locale, 'group' => $group, 'key' => $key));
                        // Check if the database is different then the files
                        $newStatus = $translation->value === $value ? Translation::STATUS_SAVED : Translation::STATUS_CHANGED;
                        if ($newStatus !== (int) $translation->status) {
                            $translation->status = $newStatus;
                        }
                        // Only replace when empty, or explicitly told so
                        if ($replace || !$translation->value) {
                            $translation->value = $value;
                        }
                        $translation->save();
                        $counter++;
                    }
                }
            }
        }
        return $counter;
    }

Usage Example

 public function postImport()
 {
     $replace = Input::get('replace', false);
     $counter = $this->manager->importTranslations($replace);
     return Response::json(array('status' => 'ok', 'counter' => $counter));
 }
All Usage Examples Of Barryvdh\TranslationManager\Manager::importTranslations