romworld

JSP 17 - Properties File Editor (다국어 처리) ,JSTL fmt 활용 본문

WEB/JSP

JSP 17 - Properties File Editor (다국어 처리) ,JSTL fmt 활용

inderrom 2023. 1. 11. 11:30

1. fmt를 활용할 수 있다

<%@ taglib prefix="fmt">
  • 날짜
  • bundle
  • 숫자

 

2. bundle

 

  • java.util.properties
  • 위치 : src/패키지
  • 파일 확장자 : .properties
  • 언어구분 : 한글 -kr 영어  -en 
  • 국제화 : i18n
  • 지역화 : L10n

다국어 처리

 

1. ctrl + n -> file- > properties 

 

 

 

 

 

 

 

Downloading File /eclipse/updates - Properties Editor - OSDN

Free download page for Project Properties Editor's updates.This editor can directly edit property files written in Unicode reference characters, eliminating the need to convert to Unicode. In a...

osdn.net

 

help - install new software -add

name은 원하는 이름으로 설정

location은 위에 주소로 설정

한글이 깨지기 때문에 edit 프로그램을 실행한다.

 


 

name=" "   : 키=값

 

<bundle01.jsp>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

teglib에 fmt를 설정해준다.

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Internationalization</title>
</head>
<body>
<!--  value 
1) 한글(ko) => message_ko.properties 
2) 영어(en) => message_en.properties
-->
<fmt:setLocale value="ko"/>
<!-- bundle시작 -->
<fmt:bundle basename="resourceBundle.message">
	<p><fmt:message key="name"/></p>
	<p><fmt:message key="hello"/></p>
	
<!-- bundle 끝 -->
</fmt:bundle>
</body>
</html>

 

<fmt:setLocale/>과 <fmt:message>는 세트 같이 쓰자!

 

실행 시키면

 

한글이 깨지지 않고 출력됨


 

file을 만들 때 _ko를 생략해도 됨 -> 기본이 ko로 설정되어있다.

 


<myBundle_en.properties>

title=Java Server Pages
username=admin
password=1234

<myBundle.properties>

title=Java Server Pages
username=admin
password=1234

 

<bundle02.jsp>

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Internationalization</title>
</head>
<body>

<p>------기본(한글) 로케일-------</p>
<fmt:setLocale value="ko"/>
<fmt:bundle basename="bundle.myBundle">
	<p>제목 : <fmt:message key="title" /></p>
	<p>이름 : <fmt:message key="username" /></p>
</fmt:bundle>

<p>------영문 로케일-------</p>
<fmt:setLocale value="en"/>
<fmt:bundle basename="bundle.myBundle">
	<p>제목 : <fmt:message key="title" /></p>
	<p>이름 : <fmt:message key="username" /></p>
</fmt:bundle>

<hr />
<fmt:setBundle basename="bundle.myBundle" var="resourceBundle" />
	<p>제목 : <fmt:message key="title" bundle="${resourceBundle}" /></p>
	<fmt:message key="username" bundle="${resourceBundle}"
				var="username" />
	<p>이름 : ${username}</p>

</body>
</html>

Comments