/** * Return an url in the default locale * * @param $url * @return string */ function untranslateURL($url) { $t = app('translator') ?: new TransLaravel(); // Parse url $arrURL = parse_url($url); $segments = explode('/', $arrURL['path']); if ($t->isLocale($segments[0])) { array_shift($segments); } if (array_last($segments) == '') { array_pop($segments); } $path = implode('/', $segments); $newPath = Languages::whereValue($path); if ($newPath->count() == 0) { $newPath = $path; } else { $newPath = $newPath->first()->route; } $returnURL = ''; $returnURL .= isset($arrURL['scheme']) ? $arrURL['scheme'] . '://' : ''; $returnURL .= isset($arrURL['host']) ? $arrURL['host'] : ''; $returnURL .= isset($arrURL['port']) && $arrURL['port'] != 80 ? ':' . $arrURL['port'] : ''; $returnURL .= '/' . config('app.fallback_language') . '/' . $newPath; $returnURL .= isset($arrURL['query']) ? '?' . $arrURL['query'] : ''; $returnURL .= isset($arrURL['fragment']) ? '#' . $arrURL['fragment'] : ''; return str_replace('//', '/', $returnURL); }
/** * Adds a language to the database. * * @param string $locale * @param array $parameters * @param bool $doISO6391Check * @return bool */ public function addLanguage($locale, $parameters = [], $doISO6391Check = true) { $locale = $this->parseLocale($locale, $doISO6391Check); $languageInfo = ['abbreviation' => $locale, 'native' => '', 'english' => '', 'active' => 1]; if ($doISO6391Check) { $info = $this->getISO6391Information($locale); $languageInfo['native'] = $info['native']; $languageInfo['english'] = $info['english']; } else { if (!isset($parameters['native']) || !isset($parameters['local'])) { throw new LanguageException('You need to add the local and/or native parameter when manually adding a language.'); } $languageInfo['native'] = $parameters['native']; $languageInfo['english'] = $parameters['english']; } return Languages::create($languageInfo)->save(); }
* @package deArgonauten/TransLaravel * @author Jason de Ridder <*****@*****.**> * @copyright Jason de Ridder * @license MIT */ Route::get('/_translations/add/{locale}', function ($locale) { app('translator')->addLanguage($locale); return redirect('/_translations/languages'); }); Route::get('/_translations/{what}', function ($what) { $list = []; $header = []; switch ($what) { case 'languages': case 'language': $list = \deArgonauten\TransLaravel\Models\Languages::all(); $header = Schema::getColumnListing(config('translaravel.table_prefix') . 'languages'); break; case 'strings': case 'string': $list = \deArgonauten\TransLaravel\Models\StringTranslations::all(); $header = Schema::getColumnListing(config('translaravel.table_prefix') . 'string_translations'); break; case 'models': case 'model': $list = \deArgonauten\TransLaravel\Models\ModelTranslations::all(); $header = Schema::getColumnListing(config('translaravel.table_prefix') . 'model_translations'); break; case 'routes': case 'route': $list = \deArgonauten\TransLaravel\Models\RouteTranslations::all();