Skip to content

Commit

Permalink
Reset translatable display callback after test
Browse files Browse the repository at this point in the history
  • Loading branch information
bram-pkg committed May 11, 2023
1 parent 51dce7e commit afca412
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(array $fields = [])
$this->originalFields = $fields;

$this->displayLocalizedNameUsingCallback = self::$displayLocalizedNameByDefaultUsingCallback ?? function (Field $field, string $locale) {
return ucfirst($field->name)." ({$locale})";
return ucfirst($field->name) . " ({$locale})";
};

$this->createTranslatableFields();
Expand All @@ -79,7 +79,7 @@ public function locales(array $locales)
return $this;
}

public static function displayLocalizedNameByDefaultUsing(Closure $displayLocalizedNameByDefaultUsingCallback)
public static function displayLocalizedNameByDefaultUsing(Closure $displayLocalizedNameByDefaultUsingCallback = null)
{
static::$displayLocalizedNameByDefaultUsingCallback = $displayLocalizedNameByDefaultUsingCallback;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ protected function createTranslatedField(Field $originalField, string $locale):

$translatedField
->resolveUsing(function ($value, Model $model) use ($translatedField, $locale, $originalAttribute) {
$translatedField->attribute = 'translations_'.$originalAttribute.'_'.$locale;
$translatedField->attribute = 'translations_' . $originalAttribute . '_' . $locale;
$translatedField->panel = $this->panel;

return $model->translations[$originalAttribute][$locale] ?? '';
Expand Down Expand Up @@ -165,7 +165,7 @@ protected function onIndexPage(): bool
*/
private function createTrixUploadField(Trix $field, string $locale): Trix
{
return Trix::make('translations_'.$field->attribute.'_'.$locale)
return Trix::make('translations_' . $field->attribute . '_' . $locale)
->withFiles(
$field->getStorageDisk(),
$field->getStorageDir()
Expand Down
2 changes: 2 additions & 0 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function it_accepts_customize_the_labels_globally()

$this->assertEquals('en-title', $translatable->data[0]->name);
$this->assertEquals('fr-title', $translatable->data[1]->name);

Translatable::displayLocalizedNameByDefaultUsing();
}

/** @test */
Expand Down

0 comments on commit afca412

Please sign in to comment.