Java

Accept-Language 관련사항

MuGrammer 2016. 12. 22. 14:26


1. Accept-Language 헤더엔 어떠한 내용이 들어가는지 알아본다. 


자료출처 : https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4


14.4 Accept-Language

The Accept-Language request-header field is similar to Accept, but restricts the set of natural languages that are preferred as a response to the request. Language tags are defined in section 3.10.

       Accept-Language = "Accept-Language" ":"
                         1#( language-range [ ";" "q" "=" qvalue ] )
       language-range  = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )

Each language-range MAY be given an associated quality value which represents an estimate of the user's preference for the languages specified by that range. The quality value defaults to "q=1". For example,

       Accept-Language: da, en-gb;q=0.8, en;q=0.7

would mean: "I prefer Danish, but will accept British English and other types of English." A language-range matches a language-tag if it exactly equals the tag, or if it exactly equals a prefix of the tag such that the first tag character following the prefix is "-". The special range "*", if present in the Accept-Language field, matches every tag not matched by any other range present in the Accept-Language field.

      Note: This use of a prefix matching rule does not imply that
      language tags are assigned to languages in such a way that it is
      always true that if a user understands a language with a certain
      tag, then this user will also understand all languages with tags
      for which this tag is a prefix. The prefix rule simply allows the
      use of prefix tags if this is the case.

The language quality factor assigned to a language-tag by the Accept-Language field is the quality value of the longest language- range in the field that matches the language-tag. If no language- range in the field matches the tag, the language quality factor assigned is 0. If no Accept-Language header is present in the request, the server

SHOULD assume that all languages are equally acceptable. If an Accept-Language header is present, then all languages which are assigned a quality factor greater than 0 are acceptable.

It might be contrary to the privacy expectations of the user to send an Accept-Language header with the complete linguistic preferences of the user in every request. For a discussion of this issue, see section 15.1.4.

As intelligibility is highly dependent on the individual user, it is recommended that client applications make the choice of linguistic preference available to the user. If the choice is not made available, then the Accept-Language header field MUST NOT be given in the request.

      Note: When making the choice of linguistic preference available to
      the user, we remind implementors of  the fact that users are not
      familiar with the details of language matching as described above,
      and should provide appropriate guidance. As an example, users
      might assume that on selecting "en-gb", they will be served any
      kind of English document if British English is not available. A
      user agent might suggest in such a case to add "en" to get the
      best matching behavior.

- 주요사항은 language-range 이 부분을 좀 더 살펴본다




자료출처 : https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.12


3.10 Language Tags

A language tag identifies a natural language spoken, written, or otherwise conveyed by human beings for communication of information to other human beings. Computer languages are explicitly excluded. HTTP uses language tags within the Accept-Language and Content- Language fields.

The syntax and registry of HTTP language tags is the same as that defined by RFC 1766 [1]. In summary, a language tag is composed of 1 or more parts: A primary language tag and a possibly empty series of subtags:

        language-tag  = primary-tag *( "-" subtag )
        primary-tag   = 1*8ALPHA
        subtag        = 1*8ALPHA

White space is not allowed within the tag and all tags are case- insensitive. The name space of language tags is administered by the IANA. Example tags include:

       en, en-US, en-cockney, i-cherokee, x-pig-latin

where any two-letter primary-tag is an ISO-639 language abbreviation and any two-letter initial subtag is an ISO-3166 country code. (The last three tags above are not registered tags; all but the last are examples of tags which could be registered in future.)


 - 난 언어만 확인하면 되니까 국가보다는 언어에 대한 표준인 ISO-639를 살펴봐야한다.



ISO 639 관련자료


URL : http://www.loc.gov/standards/iso639-2/php/code_list.php



내용은 뭐 상당히 많다.. ;;;; 


내가 찾고자 항목은 한국어, 영어, 일본어, 중국어, 베트남어, 인도네이사어였으니 원하는 정보는 모두 확인 할 수 있다. 올레~~




브라우저가의 언어설정에 따라 언어를 변경하여 화면에 글씨를 표시하기 위해 위와 같은 확인 작업을 거쳤다. 


Header의 Accept-Language 를 꺼내와 위의 언어코드와 비교하여 일치하는 항목이 있을 경우 해당 언어로 변경해주면 된다.. 



반응형

'Java' 카테고리의 다른 글

web.xml url-pattern 관련 스펙  (0) 2016.08.26
[JAVA/JSP] GET방식 한글깨짐 처리  (0) 2015.04.14
[Java] SimpleDateFormat  (0) 2015.04.02
Try Catch Finally 동작순서  (0) 2014.12.31
파일읽기 기본  (0) 2013.12.31