CodeIgniter Forums
Get list of available languages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Get list of available languages (/showthread.php?tid=79697)



Get list of available languages - Ryubal - 07-21-2021

Hello guys, quick question.

Is there a built-in way to get a list of languages available? Or do I have to go the manual route, by scanning folder names in app/Language?

I'd like to provide a logged-in user with the languages available, so he can choose whichever he wants.


RE: Get list of available languages - InsiteFX - 07-21-2021

We usally add the languages that were going to use, you could create your own array and add the languages to it.

Updated 07-27-2021 Added helper method.

PHP Code:
/**
 * Get a Language directory list
 *
 * Add to your own helper.
 */
if ( ! function_exists('getLangList'))
{
 
/**
 * getLangList ()
 * -------------------------------------------------------------------
 *
 * USAGE:
 *
 *  $list = getLangList();
 *  var_dump($list);
 *
 * @return array
 */
 
function getLangList()
 {
 
helper('filesystem');

 
$temp directory_map(APPPATH.'/Language'1);

 foreach (
$temp as $key => $value)
 {
    $list[] = substr($value0, -1);
 }

 return 
$list;
 }


This method willl return to you an array of all languages in the app/Language folder.