OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / cmd / gotext / message.go
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 // TODO: these definitions should be moved to a package so that the can be used
8 // by other tools.
9
10 // The file contains the structures used to define translations of a certain
11 // messages.
12 //
13 // A translation may have multiple translations strings, or messages, depending
14 // on the feature values of the various arguments. For instance, consider
15 // a hypothetical translation from English to English, where the source defines
16 // the format string "%d file(s) remaining". A completed translation, expressed
17 // in JS, for this format string could look like:
18 //
19 // {
20 //     "Key": [
21 //         "\"%d files(s) remaining\""
22 //     ],
23 //     "Original": {
24 //         "Msg": "\"%d files(s) remaining\""
25 //     },
26 //     "Translation": {
27 //             "Select": {
28 //                 "Feature": "plural",
29 //             "Arg": 1,
30 //             "Case": {
31 //                 "one":   { "Msg": "1 file remaining" },
32 //                 "other": { "Msg": "%d files remaining" }
33 //             },
34 //         },
35 //     },
36 //     "Args": [
37 //         {
38 //             "ID": 2,
39 //             "Type": "int",
40 //             "UnderlyingType": "int",
41 //             "Expr": "nFiles",
42 //             "Comment": "number of files remaining",
43 //             "Position": "golang.org/x/text/cmd/gotext/demo.go:34:3"
44 //         }
45 //     ],
46 //     "Position": "golang.org/x/text/cmd/gotext/demo.go:33:10",
47 // }
48 //
49 // Alternatively, the Translation section could be written as:
50 //
51 //     "Translation": {
52 //             "Msg": "%d %[files]s remaining",
53 //         "Var": {
54 //             "files" : {
55 //                 "Select": {
56 //                         "Feature": "plural",
57 //                     "Arg": 1,
58 //                     "Case": {
59 //                         "one":   { "Msg": "file" },
60 //                         "other": { "Msg": "files" }
61 //                     }
62 //                 }
63 //             }
64 //         }
65 //     }
66
67 // A Translation describes a translation for a single language for a single
68 // message.
69 type Translation struct {
70         // Key contains a list of identifiers for the message. If this list is empty
71         // Original is used as the key.
72         Key               []string `json:"key,omitempty"`
73         Original          Text     `json:"original"`
74         Translation       Text     `json:"translation"`
75         ExtractedComment  string   `json:"extractedComment,omitempty"`
76         TranslatorComment string   `json:"translatorComment,omitempty"`
77
78         Args []Argument `json:"args,omitempty"`
79
80         // Extraction information.
81         Position string `json:"position,omitempty"` // filePosition:line
82 }
83
84 // An Argument contains information about the arguments passed to a message.
85 type Argument struct {
86         ID             interface{} `json:"id"` // An int for printf-style calls, but could be a string.
87         Type           string      `json:"type"`
88         UnderlyingType string      `json:"underlyingType"`
89         Expr           string      `json:"expr"`
90         Value          string      `json:"value,omitempty"`
91         Comment        string      `json:"comment,omitempty"`
92         Position       string      `json:"position,omitempty"`
93
94         // Features contains the features that are available for the implementation
95         // of this argument.
96         Features []Feature `json:"features,omitempty"`
97 }
98
99 // Feature holds information about a feature that can be implemented by
100 // an Argument.
101 type Feature struct {
102         Type string `json:"type"` // Right now this is only gender and plural.
103
104         // TODO: possible values and examples for the language under consideration.
105
106 }
107
108 // Text defines a message to be displayed.
109 type Text struct {
110         // Msg and Select contains the message to be displayed. Within a Text value
111         // either Msg or Select is defined.
112         Msg    string  `json:"msg,omitempty"`
113         Select *Select `json:"select,omitempty"`
114         // Var defines a map of variables that may be substituted in the selected
115         // message.
116         Var map[string]Text `json:"var,omitempty"`
117         // Example contains an example message formatted with default values.
118         Example string `json:"example,omitempty"`
119 }
120
121 // Type Select selects a Text based on the feature value associated with
122 // a feature of a certain argument.
123 type Select struct {
124         Feature string          `json:"feature"` // Name of variable or Feature type
125         Arg     interface{}     `json:"arg"`     // The argument ID.
126         Cases   map[string]Text `json:"cases"`
127 }