Skip to content

Language Determination Bug #7689

@FRReinert

Description

@FRReinert

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

  1. Use LocaleMiddleWare
MIDDLEWARE = [
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
  1. Set Languages
LANGUAGES = [
    ('en', _('English')),
    ('pt', _('Portuguese')),
]
# LANGUAGE_CODE = 'pt'
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)
TIME_ZONE = 'America/Sao_Paulo'
  1. Configure URL Paths for i18n pattern
urlpatterns = i18n_patterns(
    ...
    path('admin/', admin.site.urls),  # Django Admin
    path('sales/', include('Sales.urls')),  # DRF Router to DRF ModelViewSet actions
    ...
)
  1. Create a simple view using Django template and translate that or use the admin and then test the ModelViewSet actions with internatiolization

Expected behavior

DRF Viewsets should translate according to the URL pattern. Ex:

  • GET example.org/pt/sales/
  • GET example.org/en/sales/000001/
  • OPTIONS example.org/pt/sales/000001/
    ...

Actual behavior

Django is translating as usual but DRF Views does not.

  • Verified the Accepted-language in the request, it changes
  • Verified HTTP methods GET and OPTIONS, both gave me the result in the written language (English)
  • Verified if translation works, it does. If i use the code above, i get the Viewsets translated.
LANGUAGE_CODE = 'pt'
# OR
LANGUAGE_CODE = 'en'

Looks like the steps in How Language is Determined Is not working properly.

If there is any other setting i can test, or anything i can do to help, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions