Closed V-ed closed 6 years ago
I started thinking about how this will be implemented and came up with an object to handle lang lines : https://gist.github.com/V-ed/ffa57aec6bf646d2749a03a01c21d265
This code is not meant to be used in our Bot yet, but might be used as a template later on. This was just a proof of concept that such string could be handled by an object automatically.
This gist also doesn't include an idea I had while doing the code snippet : a LangAmountManager that would keep track of which range is used, which is available, handle different formats automatically, etc.
I'll say it again just in case : Please do not use this gist as-is, as it is not optimized, not entirely functionnal (works on a perfect scenario but as no error handling, etc) and repeats code.
Issue moved to Vhoyon/Vramework #5 via ZenHub
This could be heavily inspired by Laravel's Localization utility (https://laravel.com/docs/5.6/localization#retrieving-translation-strings) :
A new method to get those types of lines would be added to the Translatable and Dictionary objects :
langAmount()
.This
langAmount
method would take some parameters :This way, to further the example above, trying to access
AppleCount
would be like so :Another example would be this string :
Accessed this way :
In that example, if the number of variable is between 2 and 20, it will actually show the number of variables in the formatted text, and that in different languages if wanted!
We could throw a custom
NumberOutOfRangeException
(that extendsIndexOutOfBoundsException
) if the number is not between the range the line allowed :