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

Liferay DXP 7.2 Portlet多语言文件无法加载求助

Liferay DXP 7.2 Portlet多语言属性文件加载问题解决方法

1. 明确配置资源包路径

尽管官方文档标注非必填,但7.2版本部分场景下必须显式配置资源包才能加载多语言文件:

  • 在portlet.xml对应Portlet的<portlet>标签内添加:
    <resource-bundle>content.Language</resource-bundle>
    
  • 在liferay-portlet.xml对应<liferay-portlet>标签内同步添加:
    <resource-bundle>content.Language</resource-bundle>
    
  • 注意:content.Language对应resources/content/目录的包路径,属性文件名需严格遵循Language_{locale}.properties格式(如Language_es.properties、Language_en_US.properties),大小写敏感。

2. 检查打包配置,确保文件被正确包含

  • Maven项目:在pom.xml中确认resources配置包含content目录:
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>content/**</include>
                </includes>
            </resource>
        </resources>
    </build>
    
  • Gradle项目:在build.gradle中配置:
    sourceSets {
        main {
            resources {
                include 'content/**'
            }
        }
    }
    
  • 打包后解压war包,检查WEB-INF/classes/content/下是否存在所有多语言属性文件,避免打包遗漏。

3. 验证Locale匹配规则

Liferay的Locale匹配严格遵循层级规则:

  • 若系统当前Locale为es_ES,仅存在Language_es.properties时会降级使用默认文件;若Locale为es,仅存在Language_es_ES.properties也无法匹配。
  • 在JSP中添加代码查看当前生效Locale:
    <%= request.getLocale() %>
    
    根据输出结果创建完全匹配的属性文件。

4. 清除缓存并重启服务

Liferay会缓存资源包内容,修改配置或属性文件后需执行:

  • 删除Liferay服务器osgi/state目录下的缓存文件
  • 重启Liferay服务
  • 清除浏览器缓存,避免前端缓存旧翻译内容

5. 检查属性文件编码

所有Language_*.properties文件需使用UTF-8编码,特殊字符需正确转义(可通过IDE设置属性文件编码为UTF-8并自动转义,或使用native2ascii工具处理)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 16:19:55