public function testTranslationPlaceHoldersCaseInsensitivity() { $replace = ['name' => 'John', 'NAME' => 'Test']; $translation = ':name :NAME'; $expected = 'John John'; $this->assertEquals($expected, Translation::translate($translation, $replace)); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $search = Input::get('lang'); //return print_r($this->translation->all()); //return dd($this->locale->translations()); $locale_list = $this->locale->all(); if ($search) { $translation_list = $this->translation->where('translation', 'like', '%' . $search . '%')->with('translated')->paginate('100'); } else { $translation_list = $this->translation->with('translated')->paginate('100'); } //dd($translation_list); $current_locale = Translation::getLocale(); //dd($current_locale); $default_locale = Translation::getAppLocale(); //dd($default_locale); //print($locale_list[$default_locale]); //return; return view('backend.languages.index', compact('locale_list', 'current_locale', 'default_locale', 'translation_list')); }
private function assertCachingIsWorking($text, $replacements = [], $localeCode = 'en') { $hash = md5($text); // After translating this text, result should be cached // and next time we execute translate method with same // text, it should return value from cache instead of // touching the database. $this->assertEquals($text, Translation::translate($text, $replacements, $localeCode)); $this->assertTrue(Cache::has("translation.{$localeCode}")); $this->assertTrue(Cache::has("translation.{$localeCode}.{$hash}")); // Delete all translation data from database. TranslationModel::query()->delete(); LocaleModel::query()->delete(); // Execute translation again $this->assertEquals($text, Translation::translate($text, $replacements, $localeCode)); // Asserting that there are no inserted values after // translate method is executed means that db is not touched at all // and that translation and locale is cached properly. $this->assertEquals(0, TranslationModel::all()->count()); $this->assertEquals(0, LocaleModel::all()->count()); }
/** * Sets the locale cookie on every request depending * on the locale supplied in the route prefix. * * @param Request $request * @param Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $request->cookies->set('locale', Translation::getRoutePrefix()); return $next($request); }