本文整理汇总了Java中org.thymeleaf.context.Context.setLocale方法的典型用法代码示例。如果您正苦于以下问题:Java Context.setLocale方法的具体用法?Java Context.setLocale怎么用?Java Context.setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.thymeleaf.context.Context
的用法示例。
在下文中一共展示了Context.setLocale方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMembershipEmailHtml
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
public String getMembershipEmailHtml(User user) {
DateTimeFormatter formatter =
DateTimeFormatter.ISO_LOCAL_DATE
.withZone(ZoneId.of("Europe/Tallinn"));
Member member = user.getMemberOrThrow();
String memberDate = formatter.format(member.getCreatedDate());
Context ctx = new Context();
ctx.setVariable("memberNumber", member.getMemberNumber());
ctx.setVariable("firstName", user.getFirstName());
ctx.setVariable("lastName", user.getLastName());
ctx.setVariable("memberDate", memberDate);
ctx.setLocale(localeResolver.resolveLocale(request));
String htmlContent = templateEngine.process("membership", ctx);
return htmlContent;
}
示例2: sendConfirmationMail
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
@Async
public void sendConfirmationMail(final RegistrationEntity registrationEntity, final Locale locale) {
try {
final Context context = new Context();
context.setLocale(locale);
context.setVariable("registration", registrationEntity);
final Writer w = new StringWriter();
templateEngine.process("registered", context, w);
final String htmlText = w.toString();
mailSender.send(mimeMessage -> {
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.name());
message.setFrom(mailFrom);
message.setTo(registrationEntity.getEmail());
message.setSubject(messageSource.getMessage("registrationConfirmationSubject", new Object[]{registrationEntity.getEvent().getName()}, locale));
message.setText(htmlTextToPlainText(htmlText), htmlText);
});
log.info("Sent confirmation email for '{}' to '{}'.", registrationEntity.getEvent().getName(), registrationEntity.getEmail());
} catch (MailException e) {
log.warn("Could not send an email to {} for event '{}': {}", registrationEntity.getEmail(), registrationEntity.getEvent().getName(), e.getMessage());
log.debug("Full error", e);
}
}
示例3: sendEmailWithVerificationLink
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
@Override
public void sendEmailWithVerificationLink(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String emailToken, String recipientFullName) {
Assert.hasText(emailToken, "emailToken must have text");
Assert.hasText(email, "email must have text");
Assert.hasText(recipientFullName, "recipientFullName must have text");
final String fragment = emailSenderProperties.getPpUiVerificationEmailTokenArgName() + "=" + emailToken;
final String verificationUrl = toPPUIVerificationUri(xForwardedProto, xForwardedHost, xForwardedPort, fragment);
final Context ctx = new Context();
ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
ctx.setVariable(PARAM_LINK_URL, verificationUrl);
ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
ctx.setLocale(LocaleContextHolder.getLocale());// set locale to support multi-language
sendEmail(ctx, email,
PROP_EMAIL_VERIFICATION_LINK_SUBJECT,
TEMPLATE_VERIFICATION_LINK_EMAIL,
PROP_EMAIL_FROM_ADDRESS,
PROP_EMAIL_FROM_PERSONAL,
LocaleContextHolder.getLocale());
}
示例4: sendEmailToConfirmVerification
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
@Override
public void sendEmailToConfirmVerification(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String recipientFullName) {
Assert.hasText(email, "email must have text");
Assert.hasText(recipientFullName, "recipientFullName must have text");
final Context ctx = new Context();
ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
ctx.setVariable(PARAM_LINK_URL, toPPUIBaseUri(xForwardedProto, xForwardedHost, xForwardedPort));
ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
ctx.setLocale(LocaleContextHolder.getLocale());//should set Locale to support Multi-Language
sendEmail(ctx, email,
PROP_EMAIL_CONFIRM_VERIFICATION_SUBJECT,
TEMPLATE_CONFIRM_VERIFICATION_EMAIL,
PROP_EMAIL_FROM_ADDRESS,
PROP_EMAIL_FROM_PERSONAL,
LocaleContextHolder.getLocale());//
}
示例5: sendEmailWithVerificationLinkAndLang
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
@Override
public void sendEmailWithVerificationLinkAndLang(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String emailToken, String recipientFullName, String language) {
Assert.hasText(emailToken, "emailToken must have text");
Assert.hasText(email, "email must have text");
Assert.hasText(recipientFullName, "recipientFullName must have text");
final String fragment = emailSenderProperties.getPpUiVerificationEmailTokenArgName() + "=" + emailToken;
final String verificationUrl = toPPUIVerificationUri(xForwardedProto, xForwardedHost, xForwardedPort, fragment);
final Context ctx = new Context();
ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
ctx.setVariable(PARAM_LINK_URL, verificationUrl);
ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
if (language == null || language.trim().isEmpty()) {
language = "en";
}
Locale locale = new Locale(language);
ctx.setLocale(locale);// set locale to support multi-language
sendEmail(ctx, email,
PROP_EMAIL_VERIFICATION_LINK_SUBJECT,
TEMPLATE_VERIFICATION_LINK_EMAIL,
PROP_EMAIL_FROM_ADDRESS,
PROP_EMAIL_FROM_PERSONAL,
locale);
}
示例6: testThymeleafTemplate
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
@Test
@Ignore
public void testThymeleafTemplate() throws IOException, MessagingException {
ClassLoaderTemplateResolver templateResolver =
new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix("/templates/");
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(Long.valueOf(3600000L));
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(true);
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
ctx.setLocale(Locale.ENGLISH);
ctx.setVariable("username", "ricky");
ctx.setVariable("url", "http://www.thymeleaf.org");
ctx.setVariable("email", "[email protected]");
StringWriter sw = new StringWriter(1024);
templateEngine.process("registry", ctx, sw);
String output = sw.toString();
System.out.println(output);
Mail mail = Mail.newBuilder().from(from,"ricky fung")
.to(to)
.subject("测试邮件[模板邮件-Thymeleaf]")
.html(output)
.build();
client.send(mail);
}
示例7: testApp
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
@Test
@Ignore
public void testApp() throws IOException {
//use thymeleaf
ClassLoaderTemplateResolver templateResolver =
new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix("/templates/");
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(Long.valueOf(3600000L));
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(true);
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
ctx.setLocale(Locale.ENGLISH);
ctx.setVariable("username", "ricky");
ctx.setVariable("url", "http://www.thymeleaf.org");
ctx.setVariable("email", "[email protected]");
StringWriter sw = new StringWriter(1024);
templateEngine.process("registry", ctx, sw);
String output = sw.toString();
System.out.println(output);
}
示例8: getMandateEmailHtml
import org.thymeleaf.context.Context; //导入方法依赖的package包/类
public String getMandateEmailHtml() {
Context ctx = new Context();
ctx.setLocale(localeResolver.resolveLocale(request));
String htmlContent = templateEngine.process("mandate", ctx);
return htmlContent;
}