gpt4 book ai didi

java - spring 元素不显示孟加拉字体

转载 作者:行者123 更新时间:2023-11-30 08:09:56 25 4
gpt4 key购买 nike

在我的元素中,我想用孟加拉语显示一条消息。所以,我有:

样式.css

    @font-face {
font-family: 'Siyam Rupali';
src: url('../fonts/SiyamRupali.eot?version=1.070');
src: local('Siyam Rupali'),
url('../fonts/SiyamRupali.woff?version=1.070') format('woff'),
url('../fonts/SiyamRupali.ttf?version=1.070') format('truetype');
font-style: normal;

}

.tabs {
position: relative;
margin: 10px auto;
font-family: 'Siyam Rupali';

}

我在 WEB-INF 文件夹中有“message.properties”。message.properties 是:

tab1.name = \u09AC\u09BE\u0982\u09B2\u09BE

我有spring-servlet.xml

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages" />
<property name="defaultEncoding" value="UTF-8" />

</bean>

我正在使用 maven,所以,在 Pom.xml 我有:

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

在我的 jsp 页面中我有:

    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<section class="tabs">
<spring:message code="tab1.name"/>
</ssection>

但是消息显示为问号..(????).. 为什么??

最佳答案

有点晚了,但我也遇到了同样的问题,所以我想分享一下我是如何解决这个问题的,希望它能对以后的人有所帮助。此外,这不是 Bangla 字体所特有的,也适用于任何其他 unicode 字体。

首先,您的 CSS 看起来不错。这就是我添加字体的方式。这是我的 .css 文件,其中包含字体:

@font-face {
font-family: 'Siyam Rupali';

src: url('../fonts/SiyamRupali.eot');

src: local('Siyam Rupali'),
url('../fonts/SiyamRupali.eot') format('embedded-opentype'),
url('../fonts/SiyamRupali.woff') format('woff'),
url('../fonts/SiyamRupali.ttf') format('truetype');

font-style: normal;
}

body {
font-family: 'Siyam Rupali', Fallback, sans-serif;
}

您仍然可以毫无问题地在标签上使用特定的字体系列。

接下来是您的资源文件。这是 IDE 的一个众所周知的问题,它们通常不会创建具有必要编码的文件(大部分时间在 ASCII 中)。在记事本中打开消息属性文件并将它们另存为 UTF-8。此外,从您的 IDE 的文件编码设置中,确保属性文件是 UTF-8。 See this picture

接下来是配置,在您的 html(或模板页面)中添加元属性 charset='UTF-8'。

在你的 spring 配置中,(据我所知,我使用基于 java 的配置和 Thymeleaf 模板引擎,xml 配置和 jsp+jSTL View 解析器配置将是相似的)

@Configuration
public class ThymeleafConfig {

@Bean
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource resource = new ReloadableResourceBundleMessageSource();
resource.setBasename("classpath:i18n/messages");
resource.setDefaultEncoding("UTF-8");
return resource;
}

@Bean
public ServletContextTemplateResolver templateResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setPrefix("/WEB-INF/html/");
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML5");
resolver.setOrder(1);
resolver.setCharacterEncoding("UTF-8");
return resolver;
}

@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(templateResolver());
return engine;
}

@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
resolver.setCharacterEncoding("UTF-8");
return resolver;
}
}

请务必注意,您的 View 解析器 bean(在我的示例中为 ThymeleafViewResolver)必须将字符编码设置为 UTF-8 并作为消息源,使用ReloadableResourceBundleMessageSource 并指定字符编码为 UTF-8。或者相信我的话,随时随地设置 UTF-8。

希望这对您有所帮助。

关于java - spring 元素不显示孟加拉字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31987497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com