Inheritance: extends Illuminate\Database\Eloquent\Model, use trait Stevebauman\Translation\Traits\TranslationTrait
示例#1
0
 public function testTranslationPlaceHolders()
 {
     $this->assertEquals('Hi :name', Translation::translate('Hi :name'));
     $this->assertEquals('Hi John', Translation::translate('Hi :name', ['name' => 'John']));
     $translations = TranslationModel::get();
     $this->assertEquals('Hi :name', $translations->get(0)->translation);
     $this->assertEquals('Hi ___name___', $translations->get(1)->translation);
 }
示例#2
0
 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());
 }