-
Notifications
You must be signed in to change notification settings - Fork 256
ccode: Adds new C function for string token replacement in Blakod #1191
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
base: master
Are you sure you want to change the base?
ccode: Adds new C function for string token replacement in Blakod #1191
Conversation
|
Unfortunately this is still not enough for translations. In some languages, the order of elements is different, like "le bateau rouge" (French) vs. "the red boat" (English). To handle this, most substitution systems require or have optional numeric placeholders, like "%1$d" and "%2$s", and thus you can change the order of substituted items if necessary. Given this extra complexity, I wonder if you can find an existing function somewhere that implements this. No sense reinventing the wheel. |
|
|
I was thinking more of third-party code, i.e. someone who has already solved this problem. |
|
I've got it working using fmtlib and supporting a few tags: resources:
system_user_killed_test = "{1} was killed by {0} {2:d} times."
messages:
BuildStringTest(what=$,killer=$)
{
local sString;
sString = BuildString(system_user_killed_test,
Send(what,@GetTrueName),
Send(killer,@GetTrueName),
5);
debug("BuildStringTest: ", sString);
return;
}Produces: |
This commit integrates the fmtlib library for modern support of string and integer formatting arguments and placeholder-based formatting (e.g., "{0}", "{1:d}").
|
I've integrated fmtlib, which should cover the needs described above. This is new territory for me, and I ended up following header-only instructions that don’t match how we typically handle external libraries. Let me know if there’s a better way to include it. |
|
Struggling with the Linux build--sorry for the spam. Could use some guidance there if we like fmtlib as a solution. |
|
I think the issue is that the Linux build is using C++11. I’m relying on fmt features that need C++17, like |
|
This is somewhat tricky. Going to C++17 would mean upgrading the compiler on the serving machines (and the github autobuild), as well as the C++ runtime library, then rebuilding the server and hoping it works. Downgrading in the case of problems isn't guaranteed to be possible. I have done this once before but it makes me nervous. I may need to think about this one some more. |
|
I was wrong about this. The versions of gcc we have installed do support C++17 already, and in fact it's the default (which we've been overriding with C++11 due to ancient history). I've checked in the change, so if you merge you should be able to get farther. |
Awesome, thanks. Seems my build struggles are over and its now working. Ended up using an older version of fmtlib because later versions appear to have a type mismatch bug whose warnings get treated as errors and thus fail to compile. The version I ended up adding--11.1.0--should support everything we need. |
|
@Meridian59 This is ready for another round of review. |
This PR introduces the
BuildStringC function, callable from Blakod for modern string formatting using fmtlib. It supports{}tokens with positional arguments (e.g.,{0},{1},{2}) for argument reordering.Temporary Testing (to be removed before merging)
I've set up a simple test/example: Call
System::BuildStringand pass it two player objects. The resource string includes two{}tokens,{0}and{1}."{1} was killed by {0}"Example usage