1Nonterminals grammar translations translation pluralizations pluralization
2             strings comments maybe_msgctxt.
3Terminals str msgid msgid_plural msgctxt msgstr plural_form comment.
4Rootsymbol grammar.
5
6grammar ->
7  translations : '$1'.
8
9% A series of translations. It can be just comments (which are discarded and can
10% be empty anyways) or comments followed by a translation followed by other
11% translations; in the latter case, comments are attached to the translation
12% that follows them.
13translations ->
14  comments : [].
15translations ->
16  comments translation translations : [add_comments_to_translation('$2', '$1')|'$3'].
17
18translation ->
19  maybe_msgctxt msgid strings msgstr strings : {translation, #{
20    comments       => [],
21    msgid          => '$3',
22    msgstr         => '$5',
23    po_source_line => extract_line('$2')
24  }}.
25translation ->
26  maybe_msgctxt msgid strings msgid_plural strings pluralizations : {plural_translation, #{
27    comments       => [],
28    msgid          => '$3',
29    msgid_plural   => '$5',
30    msgstr         => plural_forms_map_from_list('$6'),
31    po_source_line => extract_line('$2')
32  }}.
33
34pluralizations ->
35  pluralization : ['$1'].
36pluralizations ->
37  pluralization pluralizations : ['$1'|'$2'].
38
39pluralization ->
40  msgstr plural_form strings : {'$2', '$3'}.
41
42strings ->
43  str : [extract_simple_token('$1')].
44strings ->
45  str strings : [extract_simple_token('$1')|'$2'].
46
47comments ->
48  '$empty' : [].
49comments ->
50  comment comments : [extract_simple_token('$1')|'$2'].
51
52%% For now, we ignore the msgctxt.
53maybe_msgctxt ->
54  '$empty' : [].
55maybe_msgctxt ->
56  msgctxt strings : [].
57
58Erlang code.
59
60extract_simple_token({_Token, _Line, Value}) ->
61  Value.
62
63extract_line({_Token, Line}) ->
64  Line.
65
66plural_forms_map_from_list(Pluralizations) ->
67  Tuples = lists:map(fun extract_plural_form/1, Pluralizations),
68  maps:from_list(Tuples).
69
70extract_plural_form({{plural_form, _Line, PluralForm}, String}) ->
71  {PluralForm, String}.
72
73add_comments_to_translation({TranslationType, Translation}, Comments) ->
74  {TranslationType, maps:put(comments, Comments, Translation)}.
75