Improved String.format method #5391
Replies: 2 comments 3 replies
-
It seems to me that the If you need complex formatting, then you can implement the function you need, taking into account the requirements you need. For example, I implemented a function that selects a random phrase from those matching the passed attributes:
|
Beta Was this translation helpful? Give feedback.
-
Mr. Avdeev, what you just said is one of the most insanely idiotic things I have ever heard. At no point in your rambling, incoherent response, were you even close to anything that could be considered a rational thought. Everyone in this room is now dumber for having listened to it. I award you thumbs down emoji, and may God have mercy on your soul. |
Beta Was this translation helpful? Give feedback.
-
Imagine we have theese variables
And we need to print something like this (considering there could be more characters)
Currently in GDScript it's possible to use if-else statements, or write something like this:
or
It seems to work well. We can even make a similar script for even more comlex sentences.
However, when we decide to localize our project we will notice that the scripts we made for English won't work well with other languages, since they may have different grammatical aspects like gender, case and even animacy. It would be much convenient if the language grammar was implemented inside strings, so in order to build a complete phrase we would need to call the
format
method only once.My suggestion is to make the
format
method accept expressions inside curly brackets. The example above could be written like this:As you can see, here we called the method only once and passed the dictionaries without getting elements from them beforehand, while the grammar is implemented in the template string.
With this approach developers will be able to do more flexible translations. Here's one example:
Beta Was this translation helpful? Give feedback.
All reactions