In Magento 2, the pub/static directory is where static view files are used for uploading and front page files such as CSS, JS, images, etc. Typically, when you run “magento setup: static-content: deploy”, the code will be generated from the static files in the module’s view directory into the pub/static directory, but it only generates into the en_US language – which is the default language.
In fact, in Magento 2, there are many languages to use. So how can you generate code from your static files in another specific language? This tutorial will share how to deploy specific language in Magento 2.
How to Deploy Specific Language in Magento 2: Step-by-Step Guide
Table of Contents
Step 1: View Magento Language Code List
First of all, to deploy into a specific language, you need to know what Magento language code you want to deploy. Here is a list of the language codes supported in Magento 2 (with default en_US). To view a list of language codes, type the following command:
magento info:language:list
List of Magento language codes.
Step 2: Setup Magento 2 Deploy Static Content Language
After having the list of language codes and selecting the language code you want to use, you continue to run the command to deploy. It is possible to deploy one or more languages at the same time (make sure you delete the language file you want to deploy in the pub/static directory before).
You can delete these directories directly or run the following command:
rm -rf []
For example, delete the language in the directory pub/static/frontend/Magento/luma:
rm -rf pub/static/frontend/Magento/luma/
Then run the command to deploy:
magento setup:static-content:deploy []
Example:
magento setup:static-content:deploy vi_VN magento setup:static-content:deploy en_US en_GB vi_VN
Processing of deploy.
pub/static directory before and after deploying.
Otherwise, you can also deploy each Magento language, for each specific theme. It will save time to check on a theme, before generating code for all other themes. Run the following command:
magento setup:static-content:deploy [] [-t|--theme[=""]]
Here is an example of deploying language for Luma theme:
magento setup:static-content:deploy ro_RO --theme Magento/luma
pub/static directory before and after deploying.
Conclusion
In conclusion, deploying a specific language in Magento 2 involves generating static content for your chosen language using the appropriate commands. This ensures that your store can effectively display content in multiple languages, improving user experience for global customers. Following the steps on how to deploy specific language in Magento 2, you can easily manage Magento 2 multilingual setups, ensuring smooth localization and a professional storefront for diverse audiences.
In addition, BSS Commerce also provides an easy guide to setup a multi-language store in Magento 2.