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.
7 // TODO: these definitions should be moved to a package so that the can be used
10 // The file contains the structures used to define translations of a certain
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:
21 // "\"%d files(s) remaining\""
24 // "Msg": "\"%d files(s) remaining\""
28 // "Feature": "plural",
31 // "one": { "Msg": "1 file remaining" },
32 // "other": { "Msg": "%d files remaining" }
40 // "UnderlyingType": "int",
42 // "Comment": "number of files remaining",
43 // "Position": "golang.org/x/text/cmd/gotext/demo.go:34:3"
46 // "Position": "golang.org/x/text/cmd/gotext/demo.go:33:10",
49 // Alternatively, the Translation section could be written as:
52 // "Msg": "%d %[files]s remaining",
56 // "Feature": "plural",
59 // "one": { "Msg": "file" },
60 // "other": { "Msg": "files" }
67 // A Translation describes a translation for a single language for a single
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"`
78 Args []Argument `json:"args,omitempty"`
80 // Extraction information.
81 Position string `json:"position,omitempty"` // filePosition:line
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"`
94 // Features contains the features that are available for the implementation
96 Features []Feature `json:"features,omitempty"`
99 // Feature holds information about a feature that can be implemented by
101 type Feature struct {
102 Type string `json:"type"` // Right now this is only gender and plural.
104 // TODO: possible values and examples for the language under consideration.
108 // Text defines a message to be displayed.
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
116 Var map[string]Text `json:"var,omitempty"`
117 // Example contains an example message formatted with default values.
118 Example string `json:"example,omitempty"`
121 // Type Select selects a Text based on the feature value associated with
122 // a feature of a certain argument.
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"`