Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ardean's avatar

How can I translate language from PHP file?

I want to know if I can translate a PHP file into my preferred language. I have the format in PHP Array and I'm using Laravel 10 for this project. This is what it looks like in the PHP file:

// <?php

return [ 'Since_launch' => 'Since launch', 'Today' => 'Today', 'Yesterday' => 'Yesterday', 'Last_7_Days' => 'Last 7 Days', 'Last_30_Days' => 'Last 30 Days', 'This_Month' => 'This Month', 'Last_Month' => 'Last Month', 'Ref_of_cheque' => 'Ref of cheque', ]; //

0 likes
2 replies
monahmad's avatar

Create a New Language File:

In Laravel, language files are typically stored in the resources/lang directory. Create a new language file for your preferred language. For example, if your language is French, you might create a file like fr.php in the resources/lang directory. Copy the Existing Translation Array:

Copy the existing PHP array from your provided file into the new language file. Replace the values with the translations in your preferred language. Example for French (resources/lang/fr.php):

php Copy code

Ardean's avatar

@monahmad Thank you for the answer. I have created the language file in the resources/lang. What I want to do now is to translate it. Since it uses PHP Array and has a lot of strings in there It's too time-consuming to translate it one by one.

I want to know if there is a tool or something to do to translate it automatically from PHP Array.

Please or to participate in this conversation.