Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Add currentLocale meta to form & detail #43

Merged
merged 3 commits into from
May 18, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add currentLocale meta to form & detail
d8vjork committed May 10, 2020
commit cfc8ca0e29a582b3e109c9e78db3f80f905725ec
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ export default {

data() {
return {
currentLocale: Object.keys(this.field.locales)[0]
currentLocale: this.field.currentLocale
}
},

6 changes: 1 addition & 5 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
@@ -86,14 +86,10 @@ export default {
data() {
return {
locales: Object.keys(this.field.locales),
currentLocale: null,
currentLocale: this.field.currentLocale,
}
},

mounted() {
this.currentLocale = this.locales[0] || null
},

methods: {
/*
* Set the initial, internal value for the field.
20 changes: 14 additions & 6 deletions src/Translatable.php
Original file line number Diff line number Diff line change
@@ -25,13 +25,10 @@ public function __construct($name, $attribute = null, $resolveCallback = null)
{
parent::__construct($name, $attribute, $resolveCallback);

$locales = array_map(function ($value) {
return __($value);
}, config('translatable.locales'));

$this->withMeta([
'locales' => $locales,
'indexLocale' => app()->getLocale()
'locales' => array_map(static fn ($value) => __($value), config('translatable.locales')),
'indexLocale' => app()->getLocale(),
'currentLocale' => app()->getLocale(),
]);
}

@@ -72,6 +69,17 @@ public function indexLocale($locale)
return $this->withMeta(['indexLocale' => $locale]);
}

/**
* Set the locale to display on detail and form.
*
* @param string $locale
* @return $this
*/
public function currentLocale($locale)
{
return $this->withMeta(['currentLocale' => $locale]);
}

/**
* Set the input field to a single line text field.
*/