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

Vue Storefront分类页翻译语句内商品计数变量无法渲染实际数值问题

Vue Storefront 翻译插值不生效修复方案

你遇到的$t翻译方法中{count}占位符没有被替换的问题,可按照以下步骤排查修复:

  • 优先检查getCategoryProductsTotal的类型
    如果你使用的是组合式API,getCategoryProductsTotal如果是ref或computed响应式变量,作为参数传给$t时不会自动解包,需要手动传入实际值,修改代码为:
    {{ $t('{count} items', { count: getCategoryProductsTotal.value }) }}
    
    模板中单独使用响应式变量时Vue会自动解包,所以你单独输出{{getCategoryProductsTotal}}可以正常显示数值,这是最常见的触发原因。
  • 检查翻译词条配置
    确认你对应语言包中的{count} items词条完整保留了{count}占位符,没有被修改为其他格式。
  • 检查vue-i18n版本匹配
    确认你项目中安装的vue-i18n版本和Storefront官方默认依赖的版本一致,不同大版本的插值语法规则存在差异,也会导致占位符不识别。
  • 临时兜底方案
    上述排查无效时,可拆分翻译实现同样效果:
    {{ getCategoryProductsTotal }} {{ $t('items') }}
    
    只需要在语言包中新增items对应的翻译即可。

内容的提问来源于stack exchange,提问作者Mohammed Abdella

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 05:54:01