View Source Expo.Message.Singular (expo v0.3.0)

Struct for non-plural messages.

For example:

msgid "Hello"
msgstr ""

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 section Summary


Rebalances all strings

Get the source line number of the message.

Link to this section Types

@type block() :: :msgid | :msgstr | :msgctxt
@opaque meta()
@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()}]

Link to this section Functions

@spec key(t()) :: {String.t(), String.t()}
@spec rebalance(t()) :: t()

Rebalances all strings

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



iex> Expo.Message.Singular.rebalance(%Expo.Message.Singular{
...>   msgid: ["", "hello", "\n", "", "world", ""],
...>   msgstr: ["", "hello", "\n", "", "world", ""],
...>   flags: [["one", "two"], ["three"]],
...>   references: [[{"one", 1}, {"two", 2}], ["three"]]
...> })
  msgid: ["hello\n", "world"],
  msgstr: ["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.



iex> %Expo.Messages{messages: [message]} = Expo.PO.parse_string!("""
...> msgid "foo"
...> msgstr "bar"
...> """)
iex> Expo.Message.Singular.source_line_number(message, :msgid)