Get array lang variables |
Hello!
Is there method to get an array lang file app/language/en/Test.php ? Thank you?
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 [ 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'); 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 = [ 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
Check out my GitHub repositories
First of all, thank you for your post!
I need to get the all array in file without user lang key. I want to send an array of all keys to Vue frontend and use indexes to determine keys.
Hello there !
Here is how you can achieve what you are asking: PHP Code: // Path to the language file, adapt it Want to know how the magic happens ? :-D Read more here: https://www.php.net/manual/en/function.i...xample-127 (01-19-2020, 04:17 PM)littlej Wrote: Hello there ! Thank you! It,s work, but I was hoping I could use system API)
You could try using nested arrays inside of your language files, as seen here. You can then access the values like below.
Using the same example, let's assume you've got a file living inside of app/Language/en/Test.php: Code: return [ You can now access it like so: Code: return lang('Test.lang_array_1'); To get the values inside of the lang_array's. This may seem a little tedious but it does what you'd like it to. I have to agree on not using any require's and require_once's in your code and using the systems API instead as it's more consistent and full proof should anything change internally within the framework itself. I hope that this helps ![]() (01-20-2020, 01:58 PM)JNapolitanoIT Wrote: You could try using nested arrays inside of your language files, as seen here. You can then access the values like below. Thank you! This is what I was looking for! Simple and out of the box!
(01-21-2020, 08:09 AM)mintwint Wrote:(01-20-2020, 01:58 PM)JNapolitanoIT Wrote: You could try using nested arrays inside of your language files, as seen here. You can then access the values like below. That's awesome news! Congratulations and good luck in your coding adventures. Remember, if you need help there is always someone here to assist ![]()
“A reader lives a thousand lives before he dies. The man who never reads lives only one.”
George R.R. Martin
Check out my GitHub repositories
|
Welcome Guest, Not a member yet? Register Sign In |