February 6, 2024

Magento 2 – Useful Commands for Developers – Part 3

In today’s interconnected world, catering to your audience’s preferred language can be a game-changer for any online store. Customers are more likely to engage, navigate, and ultimately purchase when they can access information in their native tongue. Luckily, Magento 2 offers built-in multilingual support, allowing store owners to create a truly global experience.

But what about custom modules you develop? As a responsible developer, it’s crucial to consider internationalization from the start. Magento’s golden rule states: wrap all output strings with the __() function to enable translation.

But manually collecting all these strings from various files and creating a CSV file sounds tedious, right? Fear not! There’s a much simpler way:

bin/magento i18n:collect-phrases

This magical command scans your entire module, identifies all strings wrapped in __(), and neatly organizes them into a CSV file. No more manual hunting!

Here’s how it works:

  1. Open your terminal and navigate to your Magento root directory.
  2. Run the command, specifying the output path and module directory:
				
					php bin/magento i18n:collect-phrases -o app/code/Webficial/Core/i18n/en_US.csv app/code/Webficial/Core/

				
			
  • -o defines the output path for your CSV file (replace with your desired location).
  • The last argument specifies the module directory where the strings reside.

That’s it! Sit back and relax while the command does its magic, creating a CSV file containing all translatable strings in your module.

Benefits of using this command:

  • Saves time and effort: No more manual string hunting!
  • Ensures completeness: Captures all translatable strings, reducing the risk of missing any.
  • Improves accuracy: Eliminates the chance of typos or errors during manual entry.

Remember:

  • The generated CSV file will contain two columns: one for the original string and another for the translated version (initially blank).
  • You need to manually fill in the translated versions for each language you want to support.

Conclusion:

Ready to unlock global reach for your Magento modules? Embrace the power of bin/magento i18n:collect-phrases and make your creations accessible to a wider audience. Stay tuned for more useful Magento commands in future blog posts!

Author

Share this post:
Facebook
Twitter
LinkedIn
WhatsApp

Discover more articles