CryoFall > Modding info

Translation System

(1/1)

Seyon:
Hello, me again.

I have a little problem with translations.
I wrote a mod to upgrade walls.

Unfortunately, I have the problem that I do not get some translations.

I have the following class:



--- Code: ---    class UpgradingSystem : ProtoSystem<UpgradingSystem>
    {

        public const string NotificationUpgrade_Title = "Cannot upgrade";

         public const string NotificationMissingTech_Message = "You lack the necessary technology.";

.....

--- End code ---
https://github.com/seyon/cryofall_mods/blob/master/SeyonWallUpgrade/Scripts/Systems/Upgrading/UpgradingSystem.cs#L30

In the same class I have the following methods:


--- Code: ---        public static void SharedShowCannotUpgradeNotification(
            ICharacter character,
            string errorMessage,
            IProtoStaticWorldObject proto)
        {
            if (IsClient)
            {
                Instance.ClientRemote_ClientShowNotificationCannotUpgrade(errorMessage, proto);
            }
            else
            {
                Instance.CallClient(
                    character,
                    _ => _.ClientRemote_ClientShowNotificationCannotUpgrade(errorMessage, proto));
            }
        }

        private void ClientRemote_ClientShowNotificationCannotUpgrade(string errorMessage, IProtoStaticWorldObject proto)
        {
            NotificationSystem.ClientShowNotification(
                NotificationUpgrade_Title,
                errorMessage,
                color: NotificationColor.Bad,
                icon: proto.Icon);
        }

--- End code ---
https://github.com/seyon/cryofall_mods/blob/master/SeyonWallUpgrade/Scripts/Systems/Upgrading/UpgradingSystem.cs#L284

(I copied the methods from the Core.)

In my "ActionState" class, I call the method as follows:


--- Code: ---            if (!this.CheckHasNeededTech(character, protoStructure))
            {
                UpgradingSystem.SharedShowCannotUpgradeNotification(character, UpgradingSystem.NotificationMissingTech_Message, protoStructure);
                return false;
            }

--- End code ---
https://github.com/seyon/cryofall_mods/blob/master/SeyonWallUpgrade/Scripts/Systems/Upgrading/UpgradingActionState.cs#L375

and I have the following translation file


--- Code: ---Scripts/Systems/Upgrading/UpgradingSystem@NotificationUpgrade_Title:
Upgrade fehlgeschlagen

Scripts/Systems/Upgrading/UpgradingSystem@NotificationMissingTech_Message:
Dir fehlt die nötige Technologie.

.....

--- End code ---
https://github.com/seyon/cryofall_mods/blob/master/SeyonWallUpgrade/Localization/de_de/SeyonWallUpgrade.de_de.txt


My problem now is that the "title" is translated correctly.
But the "message" remains untranslated.

In the translation file I used the class as namespace in which the constant is defined. (the same for both cases)

At first I thought the namespace might have to match the class in which the method is called and not where the constant is defined. However, it did not work out when I changed the message namespace to ActionState where the call happens.

Did I miss anything? Or how exactly do the translations work?

It's probably just a small mistake but I have no idea and would be happy about a little tip.

Thanks in advance.

ai_enabled:
Hi!


--- Code: ---Instance.CallClient(
    character,
    _ => _.ClientRemote_ClientShowNotificationCannotUpgrade(errorMessage, proto));

--- End code ---
This code is executed on the server side so the error message is presented in the server language which is defined in SettingsServer.xml file.

In such cases we recommend sending a enum instead of a error message text and getting the error message on the client side so it's always properly localized.
But as I can see in your case, it's not actually required as there is only one possible error message.
In that case it makes sense to remove errorMessage arg from SharedShowCannotUpgradeNotifi cation and use NotificationMissingTech_Messa ge in ClientRemote_ClientShowNotifi cationCannotUpgrade.
Regards!

Seyon:
great thank you!
I did not think of that. But of course it makes sense.

I will try it as suggested with an enum, since I already have 3 error messages and probably more to come  ;D

ai_enabled:
In case of enum — it will break compatibility with the existing save unless you mark it with an [NotPersistent] attribute like this:

--- Code: ---[NotPersistent]
public enum MyErrorCodes ...
--- End code ---

But in that case you could much more easily add error messages like this:

--- Code: ---[NotPersistent]
public enum MyErrorCodes : byte
{
    [Description("Error 1 message")]
    Error1 = 1,
   
    [Description("Error 2 message")]
    Error2 = 2
}
--- End code ---

To localize it you can use the same translation text file approach, just need to write the enum entry name and our localization system will swap [Description(...)] text with localized version during the compilation.

Regards!

Seyon:
Thanks, works great!

Navigation

[0] Message Index

Go to full version