Format Exception in Mod localization code

Discuss coding questions, pull requests, and implementation details.
Post Reply
User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Format Exception in Mod localization code

Post by DunnyOfPenwick »

I'm getting a format exception when missing a key in textdatabase.txt.

~line 517 Mod.cs

Code: Select all

        public string Localize(string key)
        {
            return TryLocalize(key) ?? string.Format(LocalizationSettings.StringDatabase.NoTranslationFoundMessage, key);
        }
It doesn't like the interpolated format string.

User avatar
Jay_H
Posts: 4061
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Format Exception in Mod localization code

Post by Jay_H »

I'll move this topic to Modder Discussion.

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Format Exception in Mod localization code

Post by DunnyOfPenwick »

I was a bit too brief in my problem description.
This is a bug in the base code that was exposed by a problem in my project.

Basically, I forgot to add a key to my textdatabase.txt file.

The Mod.Localize() method should have returned a 'No translation found for XXX...' string, but instead threw a Format Exception. This is a problem with the formatting string in the base code.

User avatar
Jay_H
Posts: 4061
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Format Exception in Mod localization code

Post by Jay_H »

Well, this could go in Mods, Translations, or Developer... I'll send it to Developer as it sounds most fundamental :D

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Format Exception in Mod localization code

Post by Interkarma »

Unity's "LocalizationSettings.StringDatabase.NoTranslationFoundMessage" isn't setup this way, so Mod.cs shouldn't be using string.Format here.

I've replaced with a custom string that accepts key in format.

https://github.com/Interkarma/daggerfal ... 1946835f95

Post Reply