Localization can increase or boost your application usages. If your site / application localized with all the applications then most of the users can use/read your systems. Can know about most effective methods. So localization is very important. Generally localizing your content is not so hard. Sometime you need to add date localization also to make your application more readable to more users. So today I will discuss how to add date localization in your application. Just follow the below steps to make it.

There are many packages for making date localization. Here I am showing the localization for this packages

Step 01: Install package with composer

composer require jenssegers/date

For Laravel you need to add the below providers in config/app.php. For upper laravel version more than 5.5+ you need not add them.

 Jenssegers\Date\DateServiceProvider 
You can add config/app.php as facades.
'Date' => Jenssegers\Date\Date::class,

Languages support

This package contains language files for the following languages:

  • Albanian
  • Arabic
  • Azerbaijani
  • Bangla
  • Basque
  • Belarusian
  • Bosnian
  • Brazilian Portuguese
  • Bulgarian
  • Catalan
  • Croatian
  • Chinese Simplified
  • Chinese Traditional
  • Czech
  • Danish
  • Dutch
  • English
  • Esperanto
  • Estonian
  • Finnish
  • French
  • Galician
  • Georgian
  • German
  • Greek
  • Hebrew
  • Hindi
  • Hungarian
  • Icelandic
  • Indonesian
  • Italian
  • Japanese
  • Kazakh
  • Korean
  • Latvian
  • Lithuanian
  • Macedonian
  • Malay
  • Norwegian
  • Nepali (नेपाली)
  • Polish
  • Portuguese
  • Persian (Farsi)
  • Romanian
  • Russian
  • Thai
  • Serbian (latin)
  • Serbian (cyrillic)
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Turkish
  • Turkmen
  • Ukrainian
  • Uzbek
  • Vietnamese
  • Welsh

Usage

The Date class extends the Carbon methods such as format and diffForHumansn and translates them based on your locale:

use Jenssegers\Date\Date;

Date::setLocale('nl');

echo Date::now()->format('l j F Y H:i:s'); // zondag 28 april 2013 21:58:16

echo Date::parse('-1 day')->diffForHumans(); // 1 dag geleden

The Date class also added some aliases and additional methods such as: ago which is an alias for diffForHumans, and the timespan method:

echo $date->timespan(); // 3 months, 1 week, 1 day, 3 hours, 20 minutes

Methods such as parse and createFromFormat also support “reverse translations”. When calling these methods with translated input, it will try to translate it to English before passing it to DateTime:

$date = Date::createFromFormat('l d F Y', 'zaterdag 21 maart 2015');

For more details your can see the package links.

Useful Tags :