【问题标题】:Localization of e-mail templates in Tapestry 5?Tapestry 5 中的电子邮件模板本地化?
【发布时间】:2018-10-05 10:59:16
【问题描述】:

Tapestry 为其页面和组件提供了出色的本地化支持。 我想发送与用户语言偏好相对应的本地化电子邮件。

有人遇到过与 Tapestry 完美集成的本地化电子邮件模板的解决方案吗? (我不介意是不是没有使用 Tapestry 的模板引擎)

【问题讨论】:

    标签: localization tapestry email-templates


    【解决方案1】:

    我为每种语言创建了一个单独的目录/包并检索了模板文件。然后使用ThreadLocale..getLocale().getLanguage() 检索当前用户的,这样我也可以使用该语言发送电子邮件。 下面是相关代码sn-p:

    public class MailSender {
        private static final String EMAIL_TEMPLATE_ROOT = "com/xxx/emailtemplate/";
    
        @Inject
        private ThreadLocale locale;
    
        public void sendEmail(..., final String emailTemplateFileName) {
            String emailTemplateFilePath = getEmailTemplateFilePath(emailTemplateFileName);
            ....
        }
    
        private String getEmailTemplateFilePath(String templateLocation) {
            String language = locale.getLocale().getLanguage();
    
            return EMAIL_TEMPLATE_ROOT + language + "/" + templateLocation;
        }
    }
    

    这并非特定于模板引擎。您可以将此技术与您的最爱一起使用。 (我保留了项目已经使用的 Velocity)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      • 2015-06-13
      • 2011-01-04
      相关资源
      最近更新 更多