Skip to content

[13.x] Add UnitEnum support to Application and Translator locale methods #59667

@juan-flores077

Description

@juan-flores077

Laravel Version

13.x

PHP Version

8.3.0

Database Driver & Version

No response

Description

The recent enum-support pass across the framework's manager classes
(#59614 base Manager::driver(), #59637 CacheManager, #59645 MailManager,
#59646 AuthManager, #59389 QueueManager, #59391 LogManager, #59420
BroadcastManager) made it natural to use enums as driver/connection/store
identifiers everywhere — except for the application's locale.

Notification::locale() already accepts a UnitEnum (#55922), but the
underlying primitives still require a string:

  • Illuminate\Foundation\Application::setLocale($locale)
  • Illuminate\Foundation\Application::setFallbackLocale($fallbackLocale)
  • Illuminate\Foundation\Application::isLocale($locale)
  • Illuminate\Translation\Translator::setLocale($locale)
  • Illuminate\Translation\Translator::setFallback($fallback)

This forces users with a typed Locale enum to call ->value everywhere:

enum Locale: string {
    case English  = 'en';
    case Japanese = 'ja';
    case Korean   = 'ko';
}

App::setLocale(Locale::Japanese->value);     // current — clunky
App::setLocale(Locale::Japanese);            // proposed — consistent with Notification::locale()

### Steps To Reproduce

`Application::setLocale`, `Application::setFallbackLocale`,
`Application::isLocale`, `Translator::setLocale`, `Translator::setFallback`
silently accept enum objects (or TypeError, depending on PHP version) and
store them as objects in config, breaking string comparisons throughout
the request lifecycle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions