Example #1
0
 /**
  * Tests that it is possible to register a generic translators factory for a domain
  * instead of having to create them manually
  *
  * @return void
  */
 public function testFallbackTranslatorWithFactory()
 {
     I18n::translator('default', 'fr_FR', function () {
         $package = new Package('default');
         $package->setMessages(['Dog' => 'Le bark']);
         return $package;
     });
     I18n::config('custom', function ($name, $locale) {
         $this->assertEquals('custom', $name);
         $package = new Package('default');
         $package->setMessages(['Cow' => 'Le moo']);
         return $package;
     });
     $translator = I18n::translator('custom', 'fr_FR');
     $this->assertEquals('Le moo', $translator->translate('Cow'));
     $this->assertEquals('Le bark', $translator->translate('Dog'));
 }