From e20facb9fd2778e8b9f26f1422145d964e49b8c3 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Wed, 13 Dec 2017 10:09:33 +0300 Subject: [PATCH] added getShortCode method --- src/Language.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Language.php b/src/Language.php index 658b2da..642b195 100644 --- a/src/Language.php +++ b/src/Language.php @@ -246,6 +246,35 @@ public static function getLongCode($short = 'default') return $long; } + /** + * Returns the language short code. + * + * @param string $long + * + * @return string + **/ + public static function getShortCode($long = 'default') + { + if ($long == 'default') { + $long = app()->getLocale(); + } + + $short = 'en'; + + // Get languages from config + $languages = config('language.all'); + + foreach ($languages as $language) { + if ($language['long'] != $long) { + continue; + } + + $short = $language['short']; + } + + return $short; + } + /** * Returns the language name. *