{0} placeholder is not replaced if the string contains apostrophes
RoboMWM opened this issue · 11 comments
Some messages simply print {0} in-game instead of the actual value. This occurs when someone attempts to enter a clan name that is shorter or longer than the specified range in the config. I'm unaware of other messages having this issue.
(I've worked around this by manually inputting the values in language.yml)
Version 2.5.5 as reported by /version simpleclans
Since I've worked around this, I do not know. However, I did have a similar issue in my plugin. In my case, it seems if the string contains apostrophe's, using {0}
doesn't work, or at least not as expected.
Try to use this for apostrophes: \'
About the original issue, could you test if it's fixed?
Well in yaml, you can use a double single quote to add a single quote in a string; no need to escape it.
The original issue occurred with the default language.yml iirc.
I had the same issue with a plugin of mine:
In my config:
´no-permission: "You don't have permission ({0}) to do this!"´
In chat: You don't have permission ({0}) to do this!
Fix:
In config:
´no-permission: "You don''t have permission ({0}) to do this!"´
P.S.: I also use MessageFormat as SimpleClans does.
Hmm, can't recall if MemorySection (the implementing class of YamlConfiguration afaik) saves strings in that manner - it usually avoids surrounding strings with quotation marks if it can avoid doing so (and thus not needing to add a double single-quote to a string) as far as I'm aware. I wonder how it's actually being read in then... since obviously the curly braces are there...
@RoboMWM what do you suggest as a fix?
using replaceall and iterating through each index within curly braces.
for (int i = 0; i < args.length; i++)
message = message.replaceAll("\\{" + i + "}", args[i]);