Beispiel #1
0
/**
 * Manages the output for a translation of a given model object, and the required field. It will
 * use the language that is being used by the user and then return the value for that given field and
 * language code.
 *
 * @param Entity $model
 * @param string $field
 */
function lang(\Tectonic\LaravelLocalisation\Translator\Translated\Entity $model, $field)
{
    $languageCode = \Tectonic\Shift\Library\Facades\CurrentLocale::code();
    if (isset($model->{$field}[$languageCode])) {
        return $model->{$field}[$languageCode];
    }
    // No Translation Available
    return '<<NTA>>';
}
Beispiel #2
0
 public function testInvalidLanguageCodeCheck()
 {
     CurrentLocale::shouldReceive('code')->once()->andReturn('lkasdljsdf');
     $this->assertEquals('<<NTA>>', lang($this->model, 'title'));
 }
Beispiel #3
0
 public function compose()
 {
     App::setLocale(CurrentLocale::code());
 }
Beispiel #4
0
 public function testLocaleSetup()
 {
     CurrentLocale::shouldReceive('code')->once()->andReturn('code');
     App::shouldReceive('setLocale')->with('code')->once();
     with(new LocaleComposer())->compose();
 }