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

Date.php: Silently fall back to en when the locale isn't supported #182

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ public static function setLocale($locale)
// Use RFC 5646 for filenames.
$resourcePath = __DIR__ . '/Lang/' . str_replace('_', '-', $locale) . '.php';

// Check if the locale is supported
if ( ! is_readable($resourcePath))
{
// Silently fall back to "en"
static::setLocale("en");
return;
}

// Symfony locale format.
$locale = str_replace('-', '_', $locale);

Expand Down
8 changes: 8 additions & 0 deletions tests/TranslationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,12 @@ public function testFormatDeclensions()
$date = new Date('10 march 2015');
$this->assertSame('10 мартa 2015', $date->format('j F Y'));
}

public function testFallbackLocale()
{
Date::setLocale('doge');

$date = new Date();
$this->assertSame('en', $date->getLocale());
}
}