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

feat: add localization in view #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions resources/views/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}"
class="text-white ml-8 no-underline dim"
>
Posts
{{ __('Posts') }}
</router-link>
</li>
<li class="leading-wide mb-4 text-sm">
Expand All @@ -32,7 +32,7 @@ class="text-white ml-8 no-underline dim"
}"
class="text-white ml-8 no-underline dim"
>
Categories
{{ __('Categories') }}
</router-link>
</li>
</ul>
14 changes: 12 additions & 2 deletions src/Nova/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Category extends TemplateResource
'id',
];

/**
* Label for resources
*
* @return string
*/
public static function label()
{
return __('Categories');
}

/**
* Get the fields displayed by the resource.
*
Expand All @@ -46,8 +56,8 @@ public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Title', 'title'),
Slug::make('Slug', 'slug')->rules('required', 'alpha_dash_or_slash'),
Text::make(__('Title'), 'title'),
Slug::make(__('Slug'), 'slug')->rules('required', 'alpha_dash_or_slash'),
];
}

Expand Down
93 changes: 54 additions & 39 deletions src/Nova/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,42 @@ public function fields(Request $request)
});

$relatedPosts = RelatedPost::where('post_id', $this->id)->pluck('related_post_id');
$showCategoryColumnInIndex = config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make('Category', 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable();
$hideCategoryColumnInIndex = config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make('Category', 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable()->hideFromIndex();
$showCategoryColumnInIndex = config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make(__('Category'), 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable();
$hideCategoryColumnInIndex = config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make(__('Category'), 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable()->hideFromIndex();

$postContent = Flexible::make('Post content', 'post_content')->hideFromIndex()
->addLayout('Text section', 'text', [
config('nova-blog.use_trix') === true ? Trix::make('Text content', 'text_content') : Markdown::make('Text content', 'text_content'),
$postContent = Flexible::make(__('Post content'), 'post_content')->hideFromIndex()
->addLayout(__('Text section'), 'text', [
config('nova-blog.use_trix') === true ? Trix::make(__('Text content'), 'text_content') : Markdown::make(__('Text content'), 'text_content'),
])
->addLayout('Image section', 'image', [
Image::make('Image', 'image')->deletable(false)->creationRules('required'),
Text::make('Image caption', 'caption'),
Text::make('Alt (image alternate text)', 'alt')
->addLayout(__('Image section'), 'image', [
Image::make(__('Image'), 'image')->deletable(false)->creationRules('required'),
Text::make(__('Image caption'), 'caption'),
Text::make(__('Alt (image alternate text)'), 'alt')
])
->addLayout('Other embed media section', 'other_media', [
Textarea::make('Embed media code (twitter, iframe, etc.)', 'media_code'),
Text::make('Media caption', 'caption')
Textarea::make(__('Embed media code (twitter, iframe, etc.)'), 'media_code'),
Text::make(__('Media caption'), 'caption')
]);

if (config('nova-blog.include_froala_texteditor_option')) {
$postContent->addLayout('Text section in Froala', 'text_froala', [
Froala::make('Text section in Froala', 'text_content_froala')
Froala::make(__('Text section in Froala'), 'text_content_froala')
]);
}

$fields = [
ID::make()->sortable(),
config('nova-blog.use_trix') === true ? Trix::make('Title', 'title')->rules('required')->alwaysShow() : Title::make('Title', 'title')->rules('required')->alwaysShow(),
config('nova-blog.hide_pinned_post_option') === true ? null : Boolean::make('Is pinned', 'is_pinned'),
config('nova-blog.include_include_in_bloglist') === true ? Boolean::make('Include in bloglist', 'include_in_bloglist') : null,
Slug::make('Slug', 'slug')->rules('required', 'alpha_dash_or_slash')->hideWhenUpdating()->hideFromIndex()->hideFromDetail(),
Select::make('Slug', 'slug_generation')->options(['original' => 'Use existing', 'new_from_title' => 'Generate new from title', 'custom' => 'Create custom'])->hideWhenCreating()->hideFromDetail()->hideFromIndex()->rules('required')->resolveUsing(function () {
config('nova-blog.use_trix') === true ? Trix::make(__('Title'), 'title')->rules('required')->alwaysShow() : Title::make(__('Title'), 'title')->rules('required')->alwaysShow(),
config('nova-blog.hide_pinned_post_option') === true ? null : Boolean::make(__('Is pinned'), 'is_pinned'),
config('nova-blog.include_include_in_bloglist') === true ? Boolean::make(__('Include in bloglist'), 'include_in_bloglist') : null,
Slug::make(__('Slug'), 'slug')->rules('required', 'alpha_dash_or_slash')->hideWhenUpdating()->hideFromIndex()->hideFromDetail(),
Select::make(__('Slug'), 'slug_generation')->options(['original' => 'Use existing', 'new_from_title' => 'Generate new from title', 'custom' => 'Create custom'])->hideWhenCreating()->hideFromDetail()->hideFromIndex()->rules('required')->resolveUsing(function () {
return $this->slug_generation ?? 'original';
}),
ConditionalContainer::make([
Slug::make('Custom slug', 'slug')->rules('required'),
Slug::make(__('Custom slug'), 'slug')->rules('required'),
])->if('slug_generation = custom'),
Text::make('Slug', function () {
Text::make(__('Slug'), function () {
$previewToken = $this->childDraft ? $this->childDraft->preview_token : $this->preview_token;
$previewPart = $previewToken ? '?preview=' . $previewToken : '';
$pagePath = $this->resource->slug;
Expand All @@ -103,58 +103,58 @@ public function fields(Request $request)
<a target='_blank' href='$pageUrl' class='text-sm py-1 px-2 text-primary no-underline dim font-bold'>$buttonText</a>
</div>";
})->asHtml()->exceptOnForms(),
DateTime::make('Published at', 'published_at')->rules('required'),
Textarea::make('Post introduction', 'post_introduction'),
config('nova-blog.include_featured_image') === true ? Image::make('Featured image', 'featured_image') : null,
DateTime::make(__('Published at'), 'published_at')->rules('required'),
Textarea::make(__('Post introduction'), 'post_introduction'),
config('nova-blog.include_featured_image') === true ? Image::make(__('Featured image'), 'featured_image') : null,
(config('nova-blog.hide_category_column_from_index') === true) ? $hideCategoryColumnInIndex : $showCategoryColumnInIndex,

$postContent,
config('nova-blog.include_related_posts_feature') === true && config('nova-blog.hide_related_posts_column_from_index') === false ?
Multiselect
::make('Related posts', 'related_posts')
::make(__('Related posts'), 'related_posts')
->options($relatedPostOptions)
->withMeta(['value' => $relatedPosts])
: null,

config('nova-blog.include_related_posts_feature') === true && config('nova-blog.hide_related_posts_column_from_index') === true ?
Multiselect
::make('Related posts', 'related_posts')
::make(__('Related posts'), 'related_posts')
->options($relatedPostOptions)
->withMeta(['value' => $relatedPosts])
->hideFromIndex()
: null,
];

if (NovaBlog::hasNovaLang()) {
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = \OptimistDigital\NovaLang\NovaLangField::make('Locale', 'locale', 'locale_parent_id')->onlyOnForms()->hideFromIndex() :
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = \OptimistDigital\NovaLang\NovaLangField::make(__('Locale'), 'locale', 'locale_parent_id')->onlyOnForms()->hideFromIndex() :
$fields[] = \OptimistDigital\NovaLang\NovaLangField::make('Locale', 'locale', 'locale_parent_id')->onlyOnForms();
} else {
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = LocaleField::make(__('Locale'), 'locale', 'locale_parent_id')
->locales($locales)
->onlyOnForms()->hideFromIndex() :
$fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
$fields[] = LocaleField::make(__('Locale'), 'locale', 'locale_parent_id')
->locales($locales)
->onlyOnForms();
}

if (count($locales) > 1) {
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = LocaleField::make(__('Locale'), 'locale', 'locale_parent_id')
->locales($locales)
->exceptOnForms()
->hideFromIndex() :
$fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
$fields[] = LocaleField::make(__('Locale'), 'locale', 'locale_parent_id')
->locales($locales)
->exceptOnForms()
->maxLocalesOnIndex(3);
} else if ($hasManyDifferentLocales) {
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = Text::make('Locale', 'locale')->exceptOnForms()->hideFromIndex() :
$fields[] = Text::make('Locale', 'locale')->exceptOnForms();
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = Text::make(__('Locale'), 'locale')->exceptOnForms()->hideFromIndex() :
$fields[] = Text::make(__('Locale'), 'locale')->exceptOnForms();
}

if (NovaBlog::hasNovaDrafts()) {
$fields[] = \OptimistDigital\NovaDrafts\DraftButton::make('Draft');
$fields[] = \OptimistDigital\NovaDrafts\PublishedField::make('State', 'published');
$fields[] = \OptimistDigital\NovaDrafts\UnpublishButton::make('Unpublish');
$fields[] = \OptimistDigital\NovaDrafts\DraftButton::make(__('Draft'));
$fields[] = \OptimistDigital\NovaDrafts\PublishedField::make(__('State'), 'published');
$fields[] = \OptimistDigital\NovaDrafts\UnpublishButton::make(__('Unpublish'));
}

$fields[] = new Panel('SEO', $this->getSeoFields());
Expand All @@ -163,7 +163,7 @@ public function fields(Request $request)
$fields[] = new Panel(
'Page data',
array_merge(
[Heading::make('Page data')->hideFromDetail()],
[Heading::make(__('Page data'))->hideFromDetail()],
$templateFieldsAndPanels['fields']
)
);
Expand All @@ -180,10 +180,10 @@ public function fields(Request $request)
protected function getSeoFields()
{
return [
Heading::make('SEO'),
Text::make('SEO Title', 'seo_title')->hideFromIndex(),
Text::make('SEO Description', 'seo_description')->hideFromIndex(),
Image::make('SEO Image', 'seo_image')->hideFromIndex(),
Heading::make(__('SEO')),
Text::make(__('SEO Title'), 'seo_title')->hideFromIndex(),
Text::make(__('SEO Description'), 'seo_description')->hideFromIndex(),
Image::make(__('SEO Image'), 'seo_image')->hideFromIndex(),
];
}

Expand All @@ -192,6 +192,21 @@ public function title()
return $this->name . ' (' . $this->slug . ')';
}

/**
* Label for resources
*
* @return string
*/
public static function label()
{
return __('Posts');
}

public static function singularLabel()
{
return __('Post');
}

public static function indexQuery(NovaRequest $request, $query)
{
$column = config('nova-blog.blog_posts_table', 'nova_blog_posts') . '.locale';
Expand Down