SimpleClans

SimpleClans

467k Downloads

{0} placeholder is not replaced if the string contains apostrophes

RoboMWM opened this issue · 11 comments

commented

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

commented

Still an issue?

commented

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.

commented

Try to use this for apostrophes: \'
About the original issue, could you test if it's fixed?

commented

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.

commented

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.

commented

(Closed by mistake)

commented

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...

commented

image
Yep, inserting another apostrophe fixes it.
I am gonna edit the language file tonight.

commented

@RoboMWM what do you suggest as a fix?

commented

using replaceall and iterating through each index within curly braces.

for (int i = 0; i < args.length; i++)
    message = message.replaceAll("\\{" + i + "}", args[i]);
commented

Seems that MessageFormat does stuff with apostrophes. The fix shouldn't require having to modify valid yaml strings IMO though ¯\_(ツ)_/¯