JSF의 국제화, 언제 메시지 번들과 리소스 번들을 사용합니까?
현지화를 위해 <resource-bundle>
및 <message-bundle>
태그를 언제 어떻게 사용해야 faces-config.xml
합니까? 이 둘의 차이점은 저에게 명확하지 않습니다.
<메시지 번들>
는 <message-bundle>
당신이 JSF 검증 / 변환 재료로 사용되는 JSF 기본 경고 / 오류 메시지를 오버라이드 (override) 할 때마다 사용됩니다. JSF 사양의 2.5.2.4 장에서 기본 경고 / 오류 메시지의 키를 찾을 수 있습니다 .
예를 들어, 기본 메시지 를 재정의하는 아래와 같은 패키지의 Messages_xx_XX.properties
파일 :com.example.i18n
required="true"
com/example/i18n/Messages_en.properties
javax.faces.component.UIInput.REQUIRED = {0}: This field is required
com/example/i18n/Messages_nl.properties
javax.faces.component.UIInput.REQUIRED = {0}: Dit veld is vereist
로케일 지정자 _xx_XX
와 파일 확장자 없이 다음과 같이 구성 할 수 있습니다 .
<message-bundle>com.example.i18n.Messages</message-bundle>
<리소스 번들>
는 <resource-bundle>
사용자가 지정 할 필요없이 전체 JSF 응용 프로그램 전체에서 사용할 수있는 지역화 된 리소스 번들을 등록 할 때마다 사용되는 <f:loadBundle>
모든 단일보기를.
예를 들어, 다음과 같은 패키지의 Text_xx_XX.properties
파일 com.example.i18n
:
com/example/i18n/Text_en.properties
main.title = Title of main page
main.head1 = Top heading of main page
main.form1.input1.label = Label of input1 of form1 of main page
com/example/i18n/Text_nl.properties
main.title = Titel van hoofd pagina
main.head1 = Bovenste kop van hoofd pagina
main.form1.input1.label = Label van input1 van form1 van hoofd pagina
로케일 지정자 _xx_XX
와 파일 확장자 없이 다음과 같이 구성 할 수 있습니다 .
<resource-bundle>
<base-name>com.example.i18n.Text</base-name>
<var>text</var>
</resource-bundle>
main.xhtml
다음과 같이 사용 됩니다.
<h:head>
<title>#{text['main.title']}</title>
</h:head>
<h:body>
<h1 id="head1">#{text['main.head1']}</h1>
<h:form id="form1">
<h:outputLabel for="input1" value="#{text['main.form1.input1.label']}" />
<h:inputText id="input1" label="#{text['main.form1.input1.label']}" />
</h:form>
</h:body>
ValidationMessages (JSR303 Bean 유효성 검사)
자바 EE 6 / JSF이 있기 때문에, 또한 그들에 의해 표현되는 새로운 JSR303 콩 검증 API있다 @NotNull
, Size
, @Max
의, 등 주석을 javax.validation.constraints
패키지로 제공된다. 이 API는 JSF 와 완전히 관련 이 없음을 이해해야합니다 . JSF의 일부는 아니지만 JSF는 유효성 검사 단계에서이를 지원 합니다. 즉, JSR303 구현 (예 : Hibernate Validator)의 존재를 확인하고 인식 한 다음 유효성 검사를 위임합니다 (사용하여 비활성화 할 수 있음 <f:validateBean disabled="true"/>
).
JSR303 사양의 4.3.1.1 장 에 따라 사용자 지정 JSR303 유효성 검사 메시지 파일은 정확히 이름 을 가져야 하며 클래스 경로 ValidationMessages_xx_XX.properties
의 루트 에 있어야합니다 (따라서 패키지가 아닙니다!).
현지화
위의 예 _xx_XX
에서 파일 이름의는 (선택 사항) 언어 및 국가 코드를 나타냅니다. 이 항목이 모두 없으면 기본 (대체) 번들이됩니다. 예를 들어 언어가 존재 _en
하는 경우 클라이언트가 Accept-Language
HTTP 요청 헤더 에서이 언어를 명시 적으로 요청했을 때 사용됩니다 . 국가에도 동일하게 적용됩니다 (예 : _en_US
또는) _en_GB
.
You can specify the supported locales for both the message and resource bundle generically in <locale-config>
element of faces-config.xml
.
<locale-config>
<default-locale>en</default-locale>
<supported-locale>nl</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>fr</supported-locale>
</locale-config>
The desired locale needs to be set via <f:view locale>
. See also Localization in JSF, how to remember selected locale per session instead of per request/view.
'IT박스' 카테고리의 다른 글
JQuery Ajax가 POST 대신 GET을 보내고 있습니다. (0) | 2020.09.25 |
---|---|
단위 테스트가 메서드가 sys.exit ()를 호출한다고 주장 할 수 있습니까? (0) | 2020.09.25 |
"실행 후 잊어 버리기"python async / await (0) | 2020.09.25 |
react-router에서 쿼리 매개 변수를 프로그래밍 방식으로 어떻게 업데이트합니까? (0) | 2020.09.25 |
Windows에서 특정 파일이 열려 있는지 어떻게 확인할 수 있습니까? (0) | 2020.09.25 |