Dima 2 роки тому
батько
коміт
1c7cb2d4ee

+ 14 - 0
internal/helpers/trans.go

@@ -1,12 +1,18 @@
 package helpers
 
 import (
+	"reflect"
+
 	"github.com/go-playground/locales/ru"
 	ut "github.com/go-playground/universal-translator"
 	"github.com/go-playground/validator/v10"
 	ruTranslations "github.com/go-playground/validator/v10/translations/ru"
 )
 
+var fieldNames = map[string]string{
+	"Tag": "Тег",
+}
+
 func GetDefaultTranslator(v *validator.Validate) (ut.Translator, error) {
 	var err error
 	localeRu := ru.New()
@@ -17,5 +23,13 @@ func GetDefaultTranslator(v *validator.Validate) (ut.Translator, error) {
 		return nil, err
 	}
 
+	v.RegisterTagNameFunc(func(field reflect.StructField) string {
+		if name, ok := fieldNames[field.Name]; ok {
+			return name
+		}
+
+		return field.Name
+	})
+
 	return trans, nil
 }

+ 1 - 1
internal/templates/admin/tag.html

@@ -1,6 +1,6 @@
 <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
     <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2">
-        <h2 class="h2">Теги</h2>
+        <h3 class="h3">Теги</h3>
         <div class="btn-toolbar mb-2 mb-md-0">
             <a class="btn btn-sm btn-primary" href="/admin/tag/add" title="Добавить">
                 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16">

+ 3 - 3
internal/templates/admin/tag_delete.html

@@ -1,6 +1,6 @@
 <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
     <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2">
-        <h2 class="h2">Удаление тега</h2>
+        <h3 class="h3">Удаление тега</h3>
     </div>
     <div class="mb-3 border-bottom border-top pb-3 pt-3">
         {{ if .used }}
@@ -10,9 +10,9 @@
         {{ end }}
     </div>
     <form method="post">
-        <a href="/admin/tag" class="btn btn-secondary">Назад</a>
+        <a href="/admin/tag" class="btn btn-sm btn-secondary">Назад</a>
         {{ if not .used }}
-        <button type="submit" class="btn btn-danger">Удалить</button>
+        <button type="submit" class="btn btn-sm btn-danger">Удалить</button>
         {{ end }}
     </form>
 </main>

+ 7 - 7
internal/templates/admin/tag_edit.html

@@ -1,13 +1,13 @@
 <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
     <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 border-bottom">
-        <h2 class="h2">{{ .title }}</h2>
+        <h3 class="h3">{{ .title }}</h3>
     </div>
     <form method="post">
         <div class="row mb-3 mt-3">
-            <label class="col-sm-2 col-form-label">Тег</label>
+            <label class="col-sm-2 col-form-label col-form-label-sm">Тег</label>
             <div class="col-sm-10">
                 {{ $tagErr := index .errors "TagForm.Tag" }}
-                <input type="text" class="form-control {{ if $tagErr }}is-invalid{{ end }}" name="tag" value="{{ .form.Tag }}">
+                <input type="text" class="form-control form-control-sm {{ if $tagErr }}is-invalid{{ end }}" name="tag" value="{{ .form.Tag }}">
                 {{ if $tagErr }}
                 <div class="invalid-feedback">
                     {{ $tagErr }}
@@ -16,10 +16,10 @@
             </div>
         </div>
         <div class="row mb-3 border-bottom pb-3">
-            <label class="col-sm-2 col-form-label">URL</label>
+            <label class="col-sm-2 col-form-label col-form-label-sm">URL</label>
             <div class="col-sm-10">
                 {{ $urlErr := index .errors "TagForm.URL" }}
-                <input type="text" class="form-control {{ if $urlErr }}is-invalid{{ end }}" name="url" value="{{ .form.URL }}">
+                <input type="text" class="form-control form-control-sm {{ if $urlErr }}is-invalid{{ end }}" name="url" value="{{ .form.URL }}">
                 {{ if $urlErr }}
                 <div class="invalid-feedback">
                     {{ $urlErr }}
@@ -27,7 +27,7 @@
                 {{ end }}
             </div>
         </div>
-        <a href="/admin/tag" class="btn btn-secondary">Назад</a>
-        <button type="submit" class="btn btn-primary">Сохранить</button>
+        <a href="/admin/tag" class="btn btn-sm btn-secondary">Назад</a>
+        <button type="submit" class="btn btn-sm btn-primary">Сохранить</button>
     </form>
 </main>