View Source Expo.Message.Singular (expo v1.1.0)
Struct for non-plural messages.
For example:
msgid "Hello"
msgstr ""
See %Expo.Message.Singular{}
for documentation on the fields of this struct.
Summary
Types
The name of the "component" of a message.
The key that identifies this message.
Metadata for this struct.
The type for this struct.
Functions
The struct for a non-plural message.
Returns the key of the message.
Merges two singular messages.
Re-balances all strings in the given message.
Gets the source line number of the message.
Types
@type block() :: :msgid | :msgstr | :msgctxt
The name of the "component" of a message.
@opaque key()
The key that identifies this message.
@opaque meta()
Metadata for this struct.
@type t() :: %Expo.Message.Singular{ __meta__: meta(), comments: [String.t()], extracted_comments: [String.t()], flags: [[String.t()]], msgctxt: Expo.Message.msgctxt() | nil, msgid: Expo.Message.msgid(), msgstr: Expo.Message.msgstr(), obsolete: boolean(), previous_messages: [Expo.Message.t()], references: [ [file :: String.t() | {file :: String.t(), line :: pos_integer()}] ] }
The type for this struct.
See %__MODULE__{}
for documentation on the fields of this struct.
Functions
The struct for a non-plural message.
The :flags
and :references
fields are defined as lists of lists in order to represent
lines in the original file. For example, this message:
#, flag1, flag2
#, flag3
#: a.ex:1
#: b.ex:2 c.ex:3
msgid "Hello"
msgstr ""
would have:
flags: [["flag1", "flag2"], ["flag3"]]
references: [["a.ex:1"], ["b.ex:2", "c.ex:3"]]
You can use Expo.Message.has_flag?/2
to make it easier to check whether a message has a given
flag.
Returns the key of the message.
The key takes the msgctxt into consideration by returning a tuple {msgctxt, msgid}
.
Both msgctxt
and msgid
are normalized to binaries (instead of keeping line information)
for easier comparison.
Examples
iex> Singular.key(%Singular{msgid: ["foo"]})
{"", "foo"}
iex> Singular.key(%Singular{msgid: ["foo"], msgctxt: ["con", "text"]})
{"context", "foo"}
Merges two singular messages.
Examples
iex> msg1 = %Expo.Message.Singular{msgid: ["test"], flags: [["one"]]}
...> msg2 = %Expo.Message.Singular{msgid: ["test"], flags: [["two"]]}
...> Expo.Message.Singular.merge(msg1, msg2)
%Expo.Message.Singular{msgid: ["test"], flags: [["two", "one"]]}
Re-balances all strings in the given message.
This function does these things:
- Puts one string per newline of
msgid
/msgstr
- Puts all flags onto one line
- Puts all references onto a separate line
Examples
iex> Singular.rebalance(%Singular{
...> msgid: ["", "hello", "\n", "", "world", ""],
...> msgstr: ["", "hello", "\n", "", "world", ""],
...> flags: [["one", "two"], ["three"]],
...> references: [[{"one", 1}, {"two", 2}], ["three"]]
...> })
%Singular{
msgid: ["hello\n", "world"],
msgstr: ["hello\n", "world"],
flags: [["one", "two", "three"]],
references: [[{"one", 1}], [{"two", 2}], ["three"]]
}
@spec source_line_number(t(), block(), default) :: non_neg_integer() | default when default: term()
Gets the source line number of the message.
Examples
iex> %Expo.Messages{messages: [message]} = Expo.PO.parse_string!("""
...> msgid "foo"
...> msgstr "bar"
...> """)
iex> Singular.source_line_number(message, :msgid)
1
iex> Singular.source_line_number(message, :msgstr)
2