Welcome Guest, Not a member yet? Register   Sign In
Get array lang variables
#2

(This post was last modified: 01-17-2020, 05:54 PM by JNapolitanoIT.)

Could you please be more specific? Are you wanting to get all of the values of an array inside of a language file? Or are you trying to get a specific language string from an array?

If it is the latter, then all you need to do is create your language file and access its values using the lang() helper function. For example let's say you have a language file called app/Language/en/Test.php. Inside of this file, you have the following array:

Code:
return [
  'key_one' => 'Value One',
  'key_two' => 'Value Two
];

All you need to do to retrieve the values from this file is call the lang() function from within your application, like so. Remember, you call these in the form of lang('Filename.Key'):
Code:
echo lang('Test.key_one');
echo lang('Test.key_two');

If you are doing this inside of a module then you need to make sure it is found by the Autoload file in app/Config/Autoload.php by putting it inside of the PSR4 array like so:
Code:
$psr4 = [
  'LibraryNamespace' => 'path/to/library/root',
];

I hope this helps you achieve your goal and any other information you need can be found here.
A reader lives a thousand lives before he dies. The man who never reads lives only one.
George R.R. Martin

Reply


Messages In This Thread
Get array lang variables - by mintwint - 01-17-2020, 01:51 PM
RE: Get array lang variables - by JNapolitanoIT - 01-17-2020, 05:53 PM
RE: Get array lang variables - by mintwint - 01-18-2020, 07:57 AM
RE: Get array lang variables - by littlej - 01-19-2020, 04:17 PM
RE: Get array lang variables - by mintwint - 01-20-2020, 01:19 PM
RE: Get array lang variables - by JNapolitanoIT - 01-20-2020, 01:58 PM
RE: Get array lang variables - by mintwint - 01-21-2020, 08:09 AM
RE: Get array lang variables - by JNapolitanoIT - 01-21-2020, 10:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB