View Source Expo.Message.Plural (expo v0.5.2)

Struct for plural messages.

For example:

msgid "Cat"
msgid_plural "Cats"
msgstr ""

See %Expo.Message.Plural{} for documentation on the fields of this struct.

Summary

Types

The "component" of a message.

The key that identifies this message.

Metadata for this struct.

t()

The type for this struct.

Functions

The struct for a plural message.

Returns the key of the message.

Merges two plural messages.

Re-balances all strings in the message.

Get the source line number of the message.

Types

@type block() :: :msgid | {:msgstr, non_neg_integer()} | :msgctxt | :msgid_plural

The "component" of a message.

@opaque key()

The key that identifies this message.

@opaque meta()

Metadata for this struct.

@type t() :: %Expo.Message.Plural{
  __meta__: meta(),
  comments: [String.t()],
  extracted_comments: [String.t()],
  flags: [[String.t()]],
  msgctxt: Expo.Message.msgctxt() | nil,
  msgid: Expo.Message.msgid(),
  msgid_plural: [Expo.Message.msgid()],
  msgstr: %{required(non_neg_integer()) => 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

Link to this function

%Expo.Message.Plural{}

View Source (struct)

The struct for a plural message.

All fields in this struct are public except for :__meta__. 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.

Link to this function

key(message)

View Source (since 0.5.0)
@spec key(t()) :: key()

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> Plural.key(%Plural{msgid: ["cat"], msgid_plural: ["cats"]})
{"", "cat"}
Link to this function

merge(message1, message2)

View Source (since 0.5.0)
@spec merge(t(), t()) :: t()

Merges two plural messages.

Examples

iex> msg1 = %Expo.Message.Plural{msgid: ["test"], msgid_plural: ["one"], flags: [["one"]], msgstr: %{0 => "une"}}
...> msg2 = %Expo.Message.Plural{msgid: ["test"], msgid_plural: ["two"], flags: [["two"]], msgstr: %{2 => "deux"}}
...> Expo.Message.Plural.merge(msg1, msg2)
%Expo.Message.Plural{msgid: ["test"], msgid_plural: ["two"], flags: [["two", "one"]], msgstr: %{0 => "une", 2 => "deux"}}
@spec rebalance(t()) :: t()

Re-balances all strings in the message.

This function does these things:

  • Put one string per newline of msgid/msgid_plural/msgstr
  • Put all flags onto one line
  • Put all references onto a separate line

Examples

iex> Plural.rebalance(%Plural{
...>   msgid: ["", "hello", "\n", "", "world", ""],
...>   msgid_plural: ["", "hello", "\n", "", "world", ""],
...>   msgstr: %{0 => ["", "hello", "\n", "", "world", ""]},
...>   flags: [["one", "two"], ["three"]],
...>   references: [[{"one", 1}, {"two", 2}], ["three"]]
...> })
%Plural{
  msgid: ["hello\n", "world"],
  msgid_plural: ["hello\n", "world"],
  msgstr: %{0 => ["hello\n", "world"]},
  flags: [["one", "two", "three"]],
  references: [[{"one", 1}], [{"two", 2}], ["three"]]
}
Link to this function

source_line_number(message, block, default \\ nil)

View Source
@spec source_line_number(t(), block(), default) :: non_neg_integer() | default
when default: term()

Get the source line number of the message.

Examples

iex> %Expo.Messages{messages: [message]} = Expo.PO.parse_string!("""
...> msgid "foo"
...> msgid_plural "foos"
...> msgstr[0] "bar"
...> """)
iex> Plural.source_line_number(message, :msgid)
1
iex> Plural.source_line_number(message, {:msgstr, 0})
3