Skip to content

Instantly share code, notes, and snippets.

@sebdesign
Created February 7, 2018 15:48
Show Gist options
  • Save sebdesign/6ae97bcf698aff3a725944457300f6cf to your computer and use it in GitHub Desktop.
Save sebdesign/6ae97bcf698aff3a725944457300f6cf to your computer and use it in GitHub Desktop.
Fix Carbon localization
# app/Providers/AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Carbon;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
/**
* Set the current translator locale and translations.
*
* This macro overrides Carbon\Carbon@setLocale(),
* because the greek translations have mistakes,
* and we need to replace them with our own.
*
* @link https://github.com/briannesbitt/Carbon/pull/1031
*/
Carbon::macro('localize', function ($locale) {
static::translator()->setLocale($locale);
static::translator()->addResource('array', trans('carbon', [], $locale), $locale);
});
Carbon::localize($this->app->getLocale());
}
}
# resources/lang/el/carbon.php
<?php
/*
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'year' => '1 χρόνος|:count χρόνια',
'y' => '1 χρόνος|:count χρόνια',
'month' => '1 μήνας|:count μήνες',
'm' => '1 μήνας|:count μήνες',
'week' => '1 εβδομάδα|:count εβδομάδες',
'w' => '1 εβδομάδα|:count εβδομάδες',
'day' => '1 μέρα|:count μέρες',
'd' => '1 μέρα|:count μέρες',
'hour' => '1 ώρα|:count ώρες',
'h' => '1 ώρα|:count ώρες',
'minute' => '1 λεπτό|:count λεπτά',
'min' => '1 λεπτό|:count λεπτά',
'second' => '1 δευτερόλεπτο|:count δευτερόλεπτα',
's' => '1 δευτερόλεπτο|:count δευτερόλεπτα',
'ago' => 'πριν από :time',
'from_now' => 'σε :time από τώρα',
'after' => ':time μετά',
'before' => ':time πριν',
];
# resources/lang/en/carbon.php
<?php
/*
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'year' => '1 year|:count years',
'y' => '1yr|:countyrs',
'month' => '1 month|:count months',
'm' => '1mo|:countmos',
'week' => '1 week|:count weeks',
'w' => '1w|:countw',
'day' => '1 day|:count days',
'd' => '1d|:countd',
'hour' => '1 hour|:count hours',
'h' => '1h|:counth',
'minute' => '1 minute|:count minutes',
'min' => '1m|:countm',
'second' => '1 second|:count seconds',
's' => '1s|:counts',
'ago' => ':time ago',
'from_now' => ':time from now',
'after' => ':time after',
'before' => ':time before',
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment