태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

Grails 1.0.3 발표 소식과 함께 홈페이지를 통해 i18n-templates 플러그인(plugin) 역시 업그레이드 되었다.

i18n-templates 플러그인은 i18n을 적용한 scaffolding templates을 제공하여 완전히 국제화 가능한 애플리케이션을 생성하도록 한다. 이 템플릿은 Grails에 의해 제공되는 기본적인 템플릿과 동일하지만, i18n이 적용된다는 것만 다르다.

현재 i18n-templates 플러그인은 Grails 1.0.3 버전에 맞도록 변경되었다.

설치
애플리케이션의 최상위 디렉토리에서 아래와 같이 명령을 실행한다.

grails install-plugin i18n-templates

more..


사용법
애플리케이션에서 i18n 리소스 번들(resource bundles)은 페이지 제목, 헤더(header) 레이블(label), 속성 레이블, 버튼 레이블, 피드백 메시지를 해결하기 위해 사용된다. 이 텍스트들은 수작업으로 추가될 필요가 있다. 그러나, 어떠한 메시지도 추가하지 않으면, Grails 애플리케이션은 기본적인 템플릿이 사용되는 것처럼 출력(render) 된다. 이는 기본적인 템플릿에 의해 사용되는 텍스트와 동일한 텍스트를 기본적으로 사용함으로써 처리된다.

만일 텍스트를 커스터마이즈 또는 번역하기 원하면 도메인 클래스를 위한 i18n 리소스 번들에 다음과 같은 키에 대한 메시지를 추가한다.
<domainClass>.create
<domainClass>.edit
<domainClass>.list
<domainClass>.new
<domainClass>.show
<domainClass>.created
<domainClass>.updated
<domainClass>.deleted
<domainClass>.not.found
<domainClass>.<property> <-- 각 속성마다
<domainClass>.<property>.<value> <-- list constraint 내의 개별 값마다

generate-i18n-messages 스크립트를 사용하여 도메인 클래스에 대해 필요한 메시지 전부를 출력할 수 있다.

grails generate-i18n-messages <domainClass>

도메인 클래스가 패키지에 속해 있거나 Hibernate과 연결된(mapped) 클래스로부터 생성된 경우에 완전한 이름을 사용하여야 한다.
grails generate-i18n-messages <fully qualified package name>.<domainClass>

사용 예
애플리케이션이 2 개의 도메인 클래스로 구성되어 있다고 가정하자.
class Author {

static hasMany = [books:Book]
String name

static constraints = {
name(blank: false, maxSize: 50)
}
}

class Book {

Author author
String isbn
String title
String category
Float price
String description

static constraints = {
author()
isbn(blank: false, maxSize: 10)
title(blank: false, maxSize: 50)
category(inList: ["Fantasy", "Mystery", "Romance", "Thriller"])
price(min: 0F, max: 100F, nullable: true)
description(blank: true, maxSize: 500)
}
}

generate-i18n-messages 스크립트를 사용하여 간편하게 메시지들을 얻을 수 있다.

more..


애플리케이션의 언어를 변경하기 위해서 이 메시지들이 사용될 수 있다:
# Author messages

author.create=Create Author
author.edit=Edit Author
author.list=Author List
author.new=New Author
author.show=Show Author
author.created=Author {0} created
author.updated=Author {0} updated
author.deleted=Author {0} deleted
author.not.found=Author not found with ID {0}
author.id=ID
author.name=Name
author.books=Books

# Book messages

book.create=Create Book
book.edit=Edit Book
book.list=Book List
book.new=New Book
book.show=Show Book
book.created=Book {0} created
book.updated=Book {0} updated
book.deleted=Book {0} deleted
book.not.found=Book not found with ID {0}
book.id=ID
book.author=Author
book.isbn=ISBN
book.title=Title
book.category=Category
book.category.Fantasy=Fantasy
book.category.Mystery=Mystery
book.category.Romance=Romance
book.category.Thriller=Thriller
book.price=Price
book.description=Description
다음 단계로, 한글 메시지를 사용하기 위해서, grails-app/i18n/messages_ko_KR.properties 리소스 파일을 생성하여 이 메시지들을 복사하여 추가하고, 키에 대한 메시지를 한글로 편집한다.

일반적인 메시지
플러그인은 일반적인 메시지에 대한 영어과 독일어 텍스트를 이미 보유하고 있다. 아래에 보이는 바와 같다.
home=Home
create=Create
edit=Edit
update=Update
delete=Delete
delete.confirm=Are you sure?
i18n-templates 플러그인을 설치할 때, 이 테스트들은 애플리케이션의 grails-app/i18n 디렉토리 내에 i18n-templates.properties 리소스 번들로 설치된다. 만일 다른 언어로 번역하기 위해서는, 위의 메시지에 대한 번역을 역시 추가할 필요가 있다.

한글 메시지를 사용하기 위해서, grails-app/i18n/i18n-templates_ko_KR.properties 리소스 파일을 생성하여 일반적인 메시지들을 복사하여 추가하고 메시지를 한글 편집한다.

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by hwsj