i18n translations

Discussion in 'Mods' started by mardrest, Jun 21, 2020.

  1. mardrest

    mardrest Star Wrangler

    I have made a mod that uses i18n translations, but it only read the default.json and not the other files when the language it's other than english.
    The code i used are in ITranslate.cs:
    Code:
    using StardewModdingAPI;
    using StardewValley;
    using System.Collections.Generic;
    
    namespace Mod
    {
      internal class ITranslate
      {
      public static string DwarfName;
    
    
      private readonly ITranslationHelper Translations;
    
      public ITranslate(ITranslationHelper translations)
      {
    
      this.Translations = translations;
    
      DwarfName = this.Translations.Get("Dwarf.Name");
      }
      }
    }
    
    And in ModEntry.cs:
    Code:
    using StardewModdingAPI;
    using StardewValley;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace Mod
    {
        public class ModEntry: Mod, IAssetLoader
        {
            private ITranslate ITranslate;
    
            public override void Entry(IModHelper helper)
            {
                this.ITranslate = new ITranslate(helper.Translation);
            
                helper.Events.GameLoop.GameLaunched += this.OnGameLaunched;
            
                if (!helper.Translation.GetTranslations().Any())
                    this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn);
      }
      }
    }
    
    Did i miss something?
     

    Share This Page