"if" node in "message" ?

3 views
Skip to first unread message

Kevin Bailey

unread,
Nov 10, 2016, 4:34:23 PM11/10/16
to grit-users
Should it be possible to put an "if" node within a "message" ? 

  <message name="IDS_NOT_SECURE_VERBOSE_STATE" desc="An adjective or short
    <if expr="use_titlecase">
      <then>
        Not Secure
      </then>
      <else> 
        Not secure
      </else>
    </if>
  </message>  

We're seeing:

grit.exception.UnexpectedChild: An unexpected child element was encountered (on
a leaf node).: invalid child <grit.node.misc.IfNode object at 0x7f4b066ca090>
for parent message

Without this ability, we'll have to duplicate the message, which, in this case, has a huge description
that we'd rather not to duplicate.

thanks

Newton Allen

unread,
Nov 10, 2016, 4:44:32 PM11/10/16
to grit-...@googlegroups.com
Putting <if> inside a <message> isn't possible currently. If you have a long message where only the first line/sentence is different, then one workaround is to split the message into two parts, provide two variants of the first part using <if><else>, then do runtime concatenation to create the full message.

You could modify grit to support this use case, though I'm not sure how tricky that would be and I certainly wouldn't recommend it as a first resort. Note that one downside of supporting <if> inside a <message> is that it can easily hide the amount of text being sent to translators (real people). E.g. <message>Lots of text... <if expr="use_titlecase>Some Title</if> lots more text ... <if expr="is_mac">Mac-specific text</if> more text ...</message>. That would generate 4 long strings, each of which would have to be translated separately. A lot more translation work than is probably necessary.

Best,
Newton

--
You received this message because you are subscribed to the Google Groups "grit-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grit-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages