You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrestaShop 1.7可后台(BO)修改的翻译变量添加方法咨询

How to Add Editable Translatable Variables in PrestaShop 1.7 Back Office

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).

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 the translations folder (create it if it doesn’t exist). For each language you support, create a PHP file (e.g., en.php for English, fr.php for 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 yourmodule with your module’s actual name, and custom_variable_key with 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:

    1. Under "Type of translation", select "Modules translations"
    2. Choose your module from the "Module" dropdown
    3. 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'}

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 to themes/your_theme/lang/ (replace your_theme with 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:

    1. Under "Type of translation", select "Themes translations"
    2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:38:24