public function postEdit(Request $request, $group) { if (!in_array($group, $this->manager->getConfig('exclude_groups'))) { $name = $request->get('name'); $value = $request->get('value'); list($locale, $key) = explode('|', $name, 2); $translation = Translation::firstOrNew(['locale' => $locale, 'group' => $group, 'key' => $key]); $translation->value = (string) $value ?: null; $translation->status = Translation::STATUS_CHANGED; $translation->save(); return array('status' => 'ok'); } }
public function importTranslations($replace = false) { $counter = 0; foreach ($this->files->directories($this->app->langPath()) as $langPath) { $locale = basename($langPath); foreach ($this->files->files($langPath) as $file) { $info = pathinfo($file); $group = $info['filename']; if (in_array($group, $this->config['exclude_groups'])) { continue; } $translations = \Lang::getLoader()->load($locale, $group); if ($translations && is_array($translations)) { foreach (array_dot($translations) as $key => $value) { $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; }