현지화된 확장 프로그램 또는 앱에는 언어별 문자열을 제공하는 messages.json라는 파일이 하나 이상 있습니다. 이 페이지에서는 messages.json 파일의 형식을 설명합니다. 인터내셔널라이제이션 및 현지화 방법에 대한 자세한 내용은 인터내셔널라이제이션 페이지를 참고하세요.
필드 요약
다음 코드는 messages.json에 지원되는 필드를 보여줍니다. 'name' 및 'message' 필드만 필수입니다.
{
"name": {
"message": "Message text, with optional placeholders.",
"description": "Translator-aimed description of the message.",
"placeholders": {
"placeholder_name": {
"content": "A string to be placed within the message.",
"example": "Translator-aimed example of the placeholder string."
},
...
}
},
...
}
예
다음은 'prompt_for_name', 'hello', 'bye'라는 세 가지 메시지를 정의하는 messages.json 파일입니다.
{
"prompt_for_name": {
"message": "What's your name?",
"description": "Ask for the user's name"
},
"hello": {
"message": "Hello, $USER$",
"description": "Greet the user",
"placeholders": {
"user": {
"content": "$1",
"example": "Cira"
}
}
},
"bye": {
"message": "Goodbye, $USER$. Come back to $OUR_SITE$ soon!",
"description": "Say goodbye to the user",
"placeholders": {
"our_site": {
"content": "Example.com",
},
"user": {
"content": "$1",
"example": "Cira"
}
}
}
}
필드 세부정보
이 섹션에서는 messages.json 파일에 표시될 수 있는 각 필드를 설명합니다. 메시지 파일이 사용되는 방식(예: 언어에서 모든 메시지를 정의하지 않는 경우 발생하는 상황)에 관한 자세한 내용은 국제화를 참고하세요.
이름
실제로 'name'이라는 필드는 없습니다. 이 필드의 이름은 메시지의 이름으로, __MSG__name___ 또는 getMessage("_name_")에 표시되는 것과 동일한 이름입니다.
이름은 현지화된 메시지 텍스트를 가져올 수 있는 대소문자를 구분하지 않는 키입니다. 이름에는 다음 문자를 포함할 수 있습니다.
- 가나다순
- a-z
- 0-9
- _ (밑줄)
- @
다음은 예 섹션에서 가져온 이름의 세 가지 예입니다.
"prompt_for_name": {
...
},
"hello": {
...
},
"bye": {
...
}
이름 사용에 관한 자세한 예는 국제화 페이지를 참고하세요.
메시지
번역된 메시지입니다. 자리표시자가 포함될 수 있는 문자열 형식입니다. $_placeholder_name_$ (대소문자 구분 안 함)를 사용하여 특정 자리표시자를 참조합니다. 예를 들어 'our_site'라는 자리표시자를 $our_site$, $OUR_SITE$ 또는 $oUR_sITe$로 참조할 수 있습니다.
다음은 예 섹션에서 가져온 메시지의 세 가지 예입니다.
"message": "What's your name?"
...
"message": "Hello, $USER$"
...
"message": "Goodbye, $USER$. Come back to $OUR_SITE$ soon!"
문자열에 달러 기호 ($)를 넣으려면 $$. For example, use the following code to specify
the message Amount (in $):
"message": "Amount (in $$)" 를 사용하세요.
Although placeholders such as$USER$are the preferred way of referring to substitution strings (strings specified using the substitutions parameter of i18n.getMessage) you can also refer to substitution strings directly within the message. For example, the following message refers to the first three substitution strings passed intogetMessage():"message": "Params: $1, $2, $3"Despite that example, we recommend that you stick to using placeholders instead of
$_n_strings within your messages. Think of placeholders as good variable names. A week after you write your code, you'll probably forget what$1refers to, but you'll know what your placeholders refer to. For more information on placeholders and substitution strings, see the placeholders section.description
Optional. A description of the message, intended to give context or details to help the translator make the best possible translation.
Here are three examples of descriptions, taken from the Example section:
"description": "Ask for the user's name" ... "description": "Greet the user" ... "description": "Say goodbye to the user"placeholders
Optional. Defines one or more substrings to be used within the message. Here are two reasons you might want to use a placeholder:
- To define the text for a part of your message that shouldn't be translated. Examples: HTML code, trademarked names, formatting specifiers.
- To refer to a substitution string passed into
getMessage(). Example:$1.Each placeholder has a name, a "content" item, and an optional "example" item. A placeholder's name is case-insensitive and can contain the same characters as a message name.
The "content" item's value is a string that can refer to substitution strings, which are specified using the i18n.getMessage method's substitutions parameter. The value of a "content" item is typically something like "Example.com" or "$1". If you refer to a substitution string that doesn't exist, you get an empty string. The following table shows how
$_n_strings correspond to strings specified by the substitutions parameter.
substitutions parameter Value of $1 Value of $2 Value of $3 userNamevalue of userName""""["Cira", "Kathy"]"Cira""Kathy"""The "example" item (optional, but highly recommended) helps translators by showing how the content appears to the end user. For example, a placeholder for a dollar amount should have an example like
"$23.45".The following snippet, taken from the Example section, shows a "placeholders" item that contains two placeholders named "our_site" and "user". The "our_site" placeholder has no "example" item because its value is obvious from the "content" field.
"placeholders": { "our_site": { "content": "Example.com", }, "user": {"content": "$1", "example": "Cira" } }