PrestaShop 1.7可后台(BO)修改的翻译变量添加方法咨询
Hey there! I’ve helped a bunch of folks with this exact issue, so let’s break down how to create translatable variables that you can easily edit via International > Translations in the PrestaShop 1.7 back office (BO).
Option 1: Add Variables via a Custom Module (Recommended)
This is the safest approach because it avoids modifying core files or risking loss during theme updates.
Step 1: Create/Update Module Language Files
In your custom module’s directory, navigate to thetranslationsfolder (create it if it doesn’t exist). For each language you support, create a PHP file (e.g.,en.phpfor English,fr.phpfor French) with this structure:<?php global $_MODULE; $_MODULE = array(); // Add your translatable variable here $_MODULE['<{yourmodule}>custom_variable_key'] = 'Default English text for your variable';Replace
yourmodulewith your module’s actual name, andcustom_variable_keywith a unique identifier for your text.Step 2: Install/Refresh the Module
Install the module (if it’s new) or refresh it in the BO. PrestaShop will automatically scan the module’s language files and register the variables.Step 3: Edit Translations in the BO
Go to International > Translations, then:- Under "Type of translation", select "Modules translations"
- Choose your module from the "Module" dropdown
- Pick the target language and click "Modify"
You’ll see your custom variable listed—edit the text as needed!
Step 4: Use the Variable in Code/Templates
- In module PHP files: Use
$this->l('custom_variable_key') - In Smarty templates: Use
{l s='custom_variable_key' mod='yourmodule'}
- In module PHP files: Use
Option 2: Add Variables via Your Theme
If you want variables tied to your theme instead of a module:
Step 1: Edit Theme Language Files
Navigate tothemes/your_theme/lang/(replaceyour_themewith your active theme name). Open or create the language file for your target language (e.g.,en.php) and add:<?php global $_THEME_LANG; $_THEME_LANG['theme_custom_variable'] = 'Default text for theme variable';Step 2: Edit Translations in the BO
Go to International > Translations:- Under "Type of translation", select "Themes translations"
- Choose your theme and target language, then click "Modify"
Look for your custom variable in the list to edit its text.
Step 3: Use the Variable in Templates
In your theme’s Smarty files, call it with:{l s='theme_custom_variable'}
Pro Tips
- Always use unique keys for your variables to avoid conflicts with existing PrestaShop translations.
- If you’re adding multiple variables, group them logically in your language files for easier maintenance.
- After adding variables, clear PrestaShop’s cache (Advanced Parameters > Performance) to ensure the new translations are detected immediately.
内容的提问来源于stack exchange,提问作者illia chill

