Skip to content

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

Closed
bipinks wants to merge 1 commit into
laravel:13.xfrom
bipinks:feature/unit-enum-locale-methods
Closed

[13.x] Add UnitEnum support to Application and Translator locale methods#59696
bipinks wants to merge 1 commit into
laravel:13.xfrom
bipinks:feature/unit-enum-locale-methods

Conversation

@bipinks

@bipinks bipinks commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

This PR extends the recent enum-support pass across the framework's manager classes (#59614, #59637, #59645, #59646, #59389, #59391, #59420) to the application's locale primitives.

Notification::locale() already accepts a UnitEnum (#55922), but the underlying primitives still required a string, forcing users with a typed Locale enum to call ->value everywhere.

Changes

The following methods now accept \UnitEnum|string and normalize via the existing Illuminate\Support\enum_value() helper:

  • Illuminate\Foundation\Application::setLocale()
  • Illuminate\Foundation\Application::setFallbackLocale()
  • Illuminate\Foundation\Application::isLocale()
  • Illuminate\Translation\Translator::setLocale()
  • Illuminate\Translation\Translator::setFallback()

Contracts (Illuminate\Contracts\Foundation\Application, Illuminate\Contracts\Translation\Translator) updated with matching docblocks.

Usage

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

App::setLocale(Locale::Japanese);        // now works
App::setFallbackLocale(Locale::English); // now works
App::isLocale(Locale::Japanese);         // now works

Both BackedEnum (uses ->value) and pure UnitEnum (uses ->name) are supported, matching the behavior of enum_value() used elsewhere in the framework.

Tests

Added unit tests covering backed and pure enum inputs for all five methods:

  • FoundationApplicationTest::testSetLocaleAcceptsBackedEnum
  • FoundationApplicationTest::testSetLocaleAcceptsUnitEnum
  • FoundationApplicationTest::testSetFallbackLocaleAcceptsBackedEnum
  • FoundationApplicationTest::testIsLocaleAcceptsEnum
  • TranslationTranslatorTest::testSetLocaleAcceptsBackedEnum
  • TranslationTranslatorTest::testSetLocaleAcceptsUnitEnum
  • TranslationTranslatorTest::testSetFallbackAcceptsBackedEnum
  • TranslationTranslatorTest::testSetFallbackAcceptsUnitEnum

Closes #59667

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

Successfully merging this pull request may close these issues.

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

2 participants