<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: amit-eiitech</title>
    <description>The latest articles on DEV Community by amit-eiitech (@amiteiitech).</description>
    <link>https://dev.to/amiteiitech</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3420820%2F1d4519cc-05f0-4b36-b3f2-402f9c6b5e1a.png</url>
      <title>DEV Community: amit-eiitech</title>
      <link>https://dev.to/amiteiitech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amiteiitech"/>
    <language>en</language>
    <item>
      <title>Effortless Laravel Localization: Auto-Generate JSON Locale Files and Translate with Google or DeepL</title>
      <dc:creator>amit-eiitech</dc:creator>
      <pubDate>Fri, 08 Aug 2025 04:30:40 +0000</pubDate>
      <link>https://dev.to/amiteiitech/effortless-laravel-localization-auto-generate-json-locale-files-and-translate-with-google-or-deepl-2dcb</link>
      <guid>https://dev.to/amiteiitech/effortless-laravel-localization-auto-generate-json-locale-files-and-translate-with-google-or-deepl-2dcb</guid>
      <description>&lt;p&gt;When building multilingual websites or web applications in Laravel, managing localization files can quickly become a headache.&lt;/p&gt;

&lt;p&gt;If your Blade templates contain large amounts of text or you need translations across multiple languages, manually extracting and translating strings becomes repetitive and error-prone.&lt;/p&gt;

&lt;p&gt;This is where a simple CLI package can make your life easier — automatically extracting strings from Blade templates and generating translated locale JSON files in one command.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Blade File with Translatable Text
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;{{ __('Laravel has an incredibly rich ecosystem. We suggest starting with the following.') }}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package scans your Blade templates for &lt;code&gt;__()&lt;/code&gt; calls and adds them to the appropriate JSON files in &lt;code&gt;resources/lang&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing Locale Generator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://packagist.org/packages/eii/locale-generator" rel="noopener noreferrer"&gt;Locale Generator&lt;/a&gt; is a Laravel CLI package that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scans Blade templates and extracts translatable strings&lt;/li&gt;
&lt;li&gt;Generates JSON locale files for multiple languages&lt;/li&gt;
&lt;li&gt;Translates them automatically using Google Translate API or DeepL API&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Install the package
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require eii/locale-generator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Publish the config file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan vendor:publish &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Create the resources/lang directory
&lt;/h3&gt;

&lt;p&gt;If it doesn’t already exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;resources/lang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up Google Translate API
&lt;/h2&gt;

&lt;p&gt;To use Google Translate, you’ll need a Google Cloud Service Account with the Translation API enabled.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step-by-step:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to Google Cloud Console&lt;br&gt;
&lt;a href="https://console.cloud.google.com/" rel="noopener noreferrer"&gt;https://console.cloud.google.com/&lt;/a&gt;&lt;br&gt;
Sign in with your Google account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a new project&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the project selector at the top&lt;/li&gt;
&lt;li&gt;Choose New Project&lt;/li&gt;
&lt;li&gt;Give it a name and create it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enable the Translation API&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to APIs &amp;amp; Services → Library&lt;/li&gt;
&lt;li&gt;Search for &lt;code&gt;Cloud Translation API&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click Enable.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a Service Account&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to IAM &amp;amp; Admin → Service Accounts&lt;/li&gt;
&lt;li&gt;Click Create Service Account&lt;/li&gt;
&lt;li&gt;Fill in the name and description&lt;/li&gt;
&lt;li&gt;Assign the role: &lt;code&gt;Project &amp;gt; Editor&lt;/code&gt; or &lt;code&gt;Cloud Translation API User&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Generate a key file&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select your new service account&lt;/li&gt;
&lt;li&gt;Go to the Keys tab&lt;/li&gt;
&lt;li&gt;Click Add Key → Create New Key&lt;/li&gt;
&lt;li&gt;Select JSON and download the file.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save the file in your Laravel project&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move it to: &lt;code&gt;storage/app/google-credentials.json&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update your &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GOOGLE_TRANSLATE_KEY_FILE=storage/app/google-credentials.json
GOOGLE_PROJECT_ID=your-project-id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up DeepL API
&lt;/h2&gt;

&lt;p&gt;If you prefer DeepL:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create or log in to a DeepL account&lt;br&gt;
&lt;a href="https://www.deepl.com/pro-api" rel="noopener noreferrer"&gt;https://www.deepl.com/pro-api&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Get your API key&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to Account → API Keys &amp;amp; Limits&lt;/li&gt;
&lt;li&gt;Click Generate Key and copy it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update your &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DEEPL_API_KEY=your-deepl-api-key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Once your credentials are set, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan lang:extract welcome &lt;span class="nt"&gt;--locales&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ja,es,de &lt;span class="nt"&gt;--translate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;deepl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scan &lt;code&gt;welcome.blade.php&lt;/code&gt; for translatable text&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;ja.json&lt;/code&gt;, &lt;code&gt;es.json&lt;/code&gt;, and &lt;code&gt;de.json&lt;/code&gt; in resources/lang&lt;/li&gt;
&lt;li&gt;Automatically translate the content using DeepL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can specify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--locales&lt;/code&gt; → Comma-separated list of language codes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--translate&lt;/code&gt; → deepl or google&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Common Language Codes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;en&lt;/code&gt; → English&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ja&lt;/code&gt; → Japanese&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;es&lt;/code&gt; → Spanish&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;de&lt;/code&gt; → German&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fr&lt;/code&gt; → French&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why This Helps&lt;br&gt;
Without this tool, you would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manually scan each Blade file&lt;/li&gt;
&lt;li&gt;Copy strings into multiple JSON files&lt;/li&gt;
&lt;li&gt;Translate each string into multiple languages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With Locale Generator, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automate extraction and file creation&lt;/li&gt;
&lt;li&gt;Translate into multiple languages in seconds&lt;/li&gt;
&lt;li&gt;Keep localization consistent and up-to-date&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Tip: Machine translations are great for speed, but always have a native speaker review important content.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>laravel</category>
      <category>cli</category>
      <category>php</category>
    </item>
  </channel>
</rss>
