mpf-mc icon indicating copy to clipboard operation
mpf-mc copied to clipboard

smart plural-ization for text widgets

Open toomanybrians opened this issue 9 years ago • 4 comments

There are many instances where you use placeholders in text widgets but where you might want to make a word singular or plural depending on the value of something else.

For example, you have a player var called "aliens" and you want a slide that says:

1 ALIEN DESTROYED

or

2 ALIENS DESTROYED

Currently this is possible with conditional events, but it's complex and you have to essentially duplicate your slide (one singular and one plural) and then make a few different events. It's even harder in a show.

The proposal is to make some kind of auto_plural setting for a widget. Something like:

widgets:
  - type: text
    text: (aliens) ALIEN[ALIENS] DESTROYED

I have no idea what the syntax for this should be without being too complex. Maybe we can have the exact format as above and figure it out? We could add auto_plural: true to look for contents in brackets?

Dunno.. I really don't have any ideas. Maybe this is something we should just use the widget player for with conditional events and write some tutorials? Though that's pretty complex, so I'm thinking there has to be a way to make this easy?

I'm open to suggestions......

toomanybrians avatar Mar 11 '17 09:03 toomanybrians

That is a classical i18n thing. We should use such a library. Usually that would be something like this http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/i18n.html. We should evaluate which library works best for us.

jabdoa2 avatar Mar 11 '17 10:03 jabdoa2

I think gettext with a custom provider might be a good choice. The call would be ngettext: https://docs.python.org/3/library/gettext.html#gettext.ngettext

jabdoa2 avatar Mar 11 '17 15:03 jabdoa2

Why not use the scoring player to set strings in either player or machine variables based on conditional events? It would not be hard to create a conditional based on the value of another player or machine variable. Perhaps not as elegant as an i18n string library, but already available in the current code. With a few good examples I'm sure users could easily make this work.

qcapen avatar Apr 25 '17 14:04 qcapen

My goal for this would be to create a string template with i18n support (should come for free with the template). At the same time i would move all the event processing to the MPF side and only push the text to MC as discussed previously. Conditional events are probably a valid workaround until then and should also provide the same functionality.

jabdoa2 avatar Apr 25 '17 14:04 jabdoa2