Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Form tabs i18n #328

Closed
Adilkhanweb opened this issue Mar 23, 2024 · 10 comments
Closed

Admin Form tabs i18n #328

Adilkhanweb opened this issue Mar 23, 2024 · 10 comments

Comments

@Adilkhanweb
Copy link

Admin Form Tabs not working correctly when using i18n for titles of the fieldsets

In my case I am using cyrillic.

from django.utils.translation import gettext_lazy as _
class Product(ModelAdmin):
    ...
    fieldsets = (
            (_("Main"), {
                "classes": ["tab"],
                'fields': [
                    ("name", "slug"),
                    ("category", "brand"),
                    ("price", "unit"),
                    ("default_variant", "discount"),
                    ("rating", "order",)
                ]
            }),
            (_("Description"), {
                "classes": ["tab"],
                "fields": ("description",)
            }),
        )

In result

<div class="tab-wrapper fieldset-" x-show="openTab == ''" style="display: none;">

Should be

<div class="tab-wrapper fieldset-description" x-show="openTab == 'description'" style="display: none;">

The titles should be slugified

@vage-mel
Copy link

vage-mel commented May 4, 2024

question is actual, can you fix?

@Adilkhanweb
Copy link
Author

Adilkhanweb commented May 4, 2024 via email

@vage-mel
Copy link

vage-mel commented May 4, 2024

problem maybe with use slugify in tabs

@vage-mel
Copy link

vage-mel commented May 4, 2024

@Adilkhanweb can union fields and stacked inline in one tab? how in django suit

@ZhangHang
Copy link

+1 same issue here

@rocketpunch-dev
Copy link

rocketpunch-dev commented May 30, 2024

Here is my solution

  • EDIT

    • unfold > templates > unfold > helpers > fieldssets_tabs.html (or copy you're static path)
      • {{ fieldset.name|slugify }} => {{ fieldset.name|slugify_allow_unicode }}
      • {% load unfold %} => {% load unfold you're custom template tag file %}
  • ADD

    • you're project > you're app > templatetags > custom template file
from django import template

from django.template.defaultfilters import stringfilter
from django.utils.text import slugify

register = template.Library()


@register.filter(is_safe=True)
@stringfilter
def slugify_allow_unicode(value):
    return slugify(value, allow_unicode=True)

@lukasvinclav
Copy link
Contributor

@rocketpunch-dev @ZhangHang @Adilkhanweb would you mind to provide exact title which is causing this issue? I just tested the functionality with special characters without any problems.

@rocketpunch-dev
Copy link

Looks like a language code issue @lukasvinclav

example

from django.utils.text import slugify
slugify('A S D F')  # 'a-s-d-f'

# korean
slugify('가 나 다 라')  # ''
slugify('가 나 다 라', allow_unicode=True)  #  '가-나-다-라'

https://docs.djangoproject.com/en/4.2/ref/utils/#django.utils.text.slugify

@lukasvinclav
Copy link
Contributor

Fixed in #422

@vage-mel
Copy link

vage-mel commented Jun 3, 2024

@Adilkhanweb can union fields and stacked inline in one tab? how in django suit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants