Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Decide on string interpolation rules for lines and commands #375

Open
McJones opened this issue Sep 28, 2023 · 0 comments
Open
Labels
proposal A proposal to add or change a feature in Yarn Spinner in a way that might affect existing users.

Comments

@McJones
Copy link
Collaborator

McJones commented Sep 28, 2023

Introduction

In the current form of Yarn Spinner we treat lines and commands the same for interpolation.
And we mostly think this is the right move, we are assuming that most of the time interpolation is going to be used to inject values into lines of dialogue to be shown to the user.
As such anything that is to be shown to the user should be culture dependant.
The issue arises when interpolation is used in commands, as an example of this:

<<declare $delay = 0.5>>
Let's wait for a half-second...
<<wait {$delay}>>
Done!

In english locales this will work as expected, but in German, for example, this will wait for five seconds, as what YS will see is: <<wait 0,5>> which will be parsed out as five seconds.
This is because we parse command parameters using the invariant culture.
The current fix for this is the format_invariant function which takes in a number and returns an invariant culture transformation of the number into a string.
This is less than ideal as <<wait {format_invariant($delay)}>> looks far less elegant than <<wait {$delay}>>.

This is the cause of:

Proposed solution

The first solution is to do nothing as the format_invariant does technically solve this solution, albeit inelegantly.

We could also make it that values are interpolated using the invariant culture.
This will solve the issue when used inside commands but means numbers presented inside of lines won't respect the current locale and always appear in the invariant (ie english) form.
To get around this limitation we'd need to make a format_local (name to be decided) function which would format an invariant number into the local culture form.
This is essentially the same as the above but flipped.

We could parse numbers inside of commands using the local culture.
As I speak english this is basically what is happening for me anyways, so I don't know how uncommon it would be to write <<wait 0,5>> instead of <<wait 0.5>>.
The main downside to this is now commands are now language dependant and the samples and docs would need to be heavily rewritten to deal with this.

Finally we could make it so that strings are interpolated invariantly inside of commands, and use the local culture when inside of lines.
This is probably the best overall compromise in my eyes.

Backwards Compatibility

This is technically breaking backwards compatibility no matter which approach is taken, but seems both uncommon enough to cause huge pains, but also important enough to justify the small break in compatibility.

Acknowledgments

Thanks to fmoo for bringing this issue to our attention

@McJones McJones added the proposal A proposal to add or change a feature in Yarn Spinner in a way that might affect existing users. label Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal A proposal to add or change a feature in Yarn Spinner in a way that might affect existing users.
Projects
None yet
Development

No branches or pull requests

1 participant