Skip to content

Commit

Permalink
added localization
Browse files Browse the repository at this point in the history
  • Loading branch information
atenfyr committed Jan 8, 2020
1 parent 4af7ffa commit d1e3d00
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 55 deletions.
2 changes: 2 additions & 0 deletions BankHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public static bool[] HasBank(int x, int y)
bool[] data = new bool[SafeTypes.Length];

if (!WorldGen.StartRoomCheck(x, y)) return data;
int iters = 0;
for (int k = WorldGen.roomY1; k <= WorldGen.roomY2; k++)
{
for (int j = WorldGen.roomX1; j <= WorldGen.roomX2; j++)
{
if (++iters > 100000) throw new Exception("we got ourselves a problem error code \"cool kid\" please report thanks");
if (Main.tile[j, k] != null && Main.tile[j, k].active())
{
ushort type = Main.tile[j, k].type;
Expand Down
37 changes: 21 additions & 16 deletions BetterTaxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;

namespace BetterTaxes
Expand All @@ -14,53 +15,57 @@ public static class UsefulThings
{
public static string ValueToCoins(int num, string zeroString = "0 copper")
{
if (zeroString == "0 copper") zeroString = "0 " + Language.GetTextValue("LegacyInterface.18");
if (num < 1) return zeroString;
return Main.ValueToCoins(num);
}

public static string ValueToCoinsWithColor(double num, string zeroString = "0 copper")
{
if (double.IsPositiveInfinity(num)) return "[c/" + Colors.CoinPlatinum.Hex3() + ":a lot of money]";
if (double.IsNegativeInfinity(num)) return "[c/" + Colors.CoinCopper.Hex3() + ":not a lot of money]";
if (double.IsNaN(num)) return "[c/" + Colors.CoinGold.Hex3() + ":something]";
if (zeroString == "0 copper") zeroString = "0 " + Language.GetTextValue("LegacyInterface.18");
if (double.IsPositiveInfinity(num)) return "[c/" + Colors.CoinPlatinum.Hex3() + ":" + Language.GetTextValue("Mods.BetterTaxes.Status.ALotOfMoney") + "]";
if (double.IsNegativeInfinity(num)) return "[c/" + Colors.CoinCopper.Hex3() + ":" + Language.GetTextValue("Mods.BetterTaxes.Status.NotALotOfMoney") + "]";
if (double.IsNaN(num)) return "[c/" + Colors.CoinGold.Hex3() + ":" + Language.GetTextValue("Mods.BetterTaxes.Status.Unknown") + "]";
return ValueToCoinsWithColor((int)num, zeroString);
}

public static string ValueToCoinsWithColor(int num, string zeroString = "0 copper")
{
if (zeroString == "0 copper") zeroString = "0 " + Language.GetTextValue("LegacyInterface.18");
string data = ValueToCoins(num, zeroString);
data = Regex.Replace(data, @"(\d+ platinum)", "[c/" + Colors.CoinPlatinum.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ gold)", "[c/" + Colors.CoinGold.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ silver)", "[c/" + Colors.CoinSilver.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ copper)", "[c/" + Colors.CoinCopper.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ " + Language.GetTextValue("LegacyInterface.15") + ")", "[c/" + Colors.CoinPlatinum.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ " + Language.GetTextValue("LegacyInterface.16") + ")", "[c/" + Colors.CoinGold.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ " + Language.GetTextValue("LegacyInterface.17") + ")", "[c/" + Colors.CoinSilver.Hex3() + ":$1]");
data = Regex.Replace(data, @"(\d+ " + Language.GetTextValue("LegacyInterface.18") + ")", "[c/" + Colors.CoinCopper.Hex3() + ":$1]");
return data;
}

public static string SecondsToHMS(int num, string zeroString = "0 seconds")
{
if (zeroString == "0 seconds") zeroString = "0 " + Language.GetTextValue("Mods.BetterTaxes.Config.Seconds");
if (num < 1) return zeroString;

string res = "";
int hours = num / 3600;
if (hours > 0) res += hours + $" hour{(hours == 1 ? "" : "s")} ";
if (hours == 1) res += hours + " " + Language.GetTextValue("Mods.BetterTaxes.Config.Hour") + " ";
if (hours > 1) res += hours + " " + Language.GetTextValue("Mods.BetterTaxes.Config.Hours") + " ";
num %= 3600;
int minutes = num / 60;
if (minutes > 0) res += minutes + $" minute{(minutes == 1 ? "" : "s")} ";
if (minutes == 1) res += minutes + " " + Language.GetTextValue("Mods.BetterTaxes.Config.Minute") + " ";
if (minutes > 1) res += minutes + " " + Language.GetTextValue("Mods.BetterTaxes.Config.Minutes") + " ";
num %= 60;
if (num > 0) res += num + $" second{(num == 1 ? "" : "s")} ";
if (num == 1) res += num + " " + Language.GetTextValue("Mods.BetterTaxes.Config.Second") + " ";
if (num > 1) res += num + " " + Language.GetTextValue("Mods.BetterTaxes.Config.Seconds") + " ";

return res.TrimEnd();
}

public static string SecondsToHMSCasual(int num, string zeroString = "a tick")
public static string SecondsToHMSCasual(int num, string zeroString = "1 tick")
{
if (zeroString == "1 tick") zeroString = "1 " + Language.GetTextValue("Mods.BetterTaxes.Config.Tick");
if (num < 1) return zeroString;

string data = SecondsToHMS(num, zeroString);
if (data == "1 second") return "a second";
if (data == "1 minute") return "a minute";
if (data == "1 hour") return "an hour";
return "every " + data;
return SecondsToHMS(num, zeroString);
}
}

Expand Down
3 changes: 3 additions & 0 deletions BetterTaxes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
<Content Include="description.txt" />
<Content Include="icon.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Localization\" />
</ItemGroup>
</Project>
21 changes: 11 additions & 10 deletions BetterTaxesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Runtime.Serialization;
using Terraria;
using Terraria.Localization;
using Terraria.ModLoader.Config;

namespace BetterTaxes
Expand Down Expand Up @@ -147,7 +148,7 @@ public class BetterTaxesConfig : ModConfig
[Header("Presets")]
[JsonIgnore]
[Label("Classic")]
[Tooltip("The classic Better Taxes experience, with basic support for Calamity and Thorium.")]
[Tooltip("$Mods.BetterTaxes.Config.ClassicD")]
public bool ClassicPreset
{
get
Expand All @@ -171,7 +172,7 @@ public bool ClassicPreset

[JsonIgnore]
[Label("Vanilla")]
[Tooltip("Replicates the Tax Collector's behavior in vanilla Terraria.")]
[Tooltip("$Mods.BetterTaxes.Config.VanillaD")]
public bool VanillaPreset
{
get
Expand All @@ -195,38 +196,38 @@ public bool VanillaPreset

[DefaultDictionaryKeyValue("")]
[Header("Configuration")]
[Tooltip("Maps \"statements\" representing game progression to rent per NPC. See the GitHub page.")]
[Tooltip("$Mods.BetterTaxes.Config.TaxRatesD")]
public Dictionary<string, SpecialInt> TaxRates
{
get;
set;
}

[Tooltip("Should this config file be subject to automatic changes made by this mod and other mods?")]
[Tooltip("$Mods.BetterTaxes.Config.IsFlexibleD")]
[DefaultValue(true)]
public bool IsFlexible
{
get;
set;
}

[Tooltip("Should the new lines of dialog be added to the Tax Collector's dialog pool?")]
[Tooltip("$Mods.BetterTaxes.Config.AddCustomDialogD")]
[DefaultValue(true)]
public bool AddCustomDialog
{
get;
set;
}

[Tooltip("Should the Tax Collector place his stored money into any personal storage tile in his room at midnight?")]
[Tooltip("$Mods.BetterTaxes.Config.EnableAutoCollectD")]
[DefaultValue(true)]
public bool EnableAutoCollect
{
get;
set;
}

[Tooltip("The amount of time between updates of the Tax Collector's money storage.")]
[Tooltip("$Mods.BetterTaxes.Config.TimeBetweenPaychecksD")]
[DefaultValue(60)]
[SliderColor(183, 88, 25)]
[Range(1, 300)]
Expand All @@ -238,7 +239,7 @@ public SpecialInt TimeBetweenPaychecks
set;
}

[Tooltip("The amount of money that the Tax Collector can hold at once.")]
[Tooltip("$Mods.BetterTaxes.Config.MoneyCapD")]
[Range(0, 100000000)]
[Increment(1000000)]
[DefaultValue(50000000)]
Expand All @@ -248,7 +249,7 @@ public SpecialInt MoneyCap
set;
}

[Tooltip("The amount to multiply tax rates by in an expert mode world.")]
[Tooltip("$Mods.BetterTaxes.Config.ExpertModeBoostD")]
[DefaultValue(1.5f)]
[SliderColor(135, 206, 250)]
[CustomModConfigItem(typeof(BoostRangeElement))]
Expand Down Expand Up @@ -287,7 +288,7 @@ public override bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, re
object data = BetterTaxes.Instance.herosMod.Call("HasPermission", whoAmI, "ModifyBTConfig");
if (data is bool) theBool = (bool)data;

if (!theBool) message = "You lack the \"Modify Better Taxes Config\" permission.";
if (!theBool) message = Language.GetTextValue("Mods.BetterTaxes.Config.NoPerms").Replace(@"%1", "Modify Better Taxes Config");
return theBool;
}
return true;
Expand Down
42 changes: 42 additions & 0 deletions Localization/en-US.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Better Taxes's language file for the coolest kids on the block

-- Dialog --
Dialog.0=Do you expect me to charge the homeless rent? Bah!
Dialog.1=Our income right now is zero, all thanks to your mistreatment of your own citizens! Bah!
Dialog.2=Bah! I've half a mind to keep all this extra coin for myself!
Dialog.3=More money for the both of us, thanks to your mass murder of "monsters!"
Dialog.4=If you're feeling genocidal, the loot some of those "powerful monsters" offer might contribute to the economy enough for me to extort more money from your citizens.
Dialog.5=How come you expect your money so often?
Dialog.6=If you were to give me something to put your coin into, like a piggy bank, you wouldn't have to talk to me anymore!
Dialog.7=You would never harvest my soul, would you?

-- Status --
Status.StatusMessage=Well, rent's getting charged at %1 every %2 per citizen, which is netting you %3 an hour. Does that answer your question?
Status.Status=Status

Status.ALotOfMoney=a lot of money
Status.NotALotOfMoney=not a lot of money
Status.Unknown=something

-- Config --
Config.ClassicD=The classic Better Taxes experience with basic support for Calamity and Thorium.
Config.VanillaD=Replicates the Tax Collector's behavior in vanilla Terraria.
Config.TaxRatesD=Maps "statements" representing game progression to rent per NPC. See the GitHub page.
Config.IsFlexibleD=Should this config file be subject to automatic changes made by this mod and other mods?
Config.AddCustomDialogD=Should the new lines of dialog be added to the Tax Collector's dialog pool?
Config.EnableAutoCollectD=Should the Tax Collector place his stored money into any personal storage tile in his room at midnight?
Config.TimeBetweenPaychecksD=The amount of time between updates of the Tax Collector's money storage.
Config.MoneyCapD=The amount of money that the Tax Collector can hold at once.
Config.ExpertModeBoostD=The amount to multiply tax rates by in an expert mode world.

Config.NoPerms=You can't perform this action because you don't have the "%1" permission.

Config.Hour=hour
Config.Hours=hours
Config.Minute=minute
Config.Minutes=minutes
Config.Second=second
Config.Seconds=seconds
Config.Tick=tick
Config.Unlimited=Unlimited
Config.Disabled=Disabled
42 changes: 42 additions & 0 deletions Localization/es-ES.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Esta traducción no es perfecta

-- Diálogo --
Dialog.0=¿Crees que puedo cobrar alquiler a la gente sin hogar? ¡Bah!
Dialog.1=¡Nuestros ingresos son cero, gracias a tu maltrato de tus propios ciudadanos! ¡Bah!
Dialog.2=¡Bah! ¡Me encantaría tomar todo este dinero extra!
Dialog.3=¡Más dinero para nosotros dos, gracias a tu asesinato en masa de "monstruos"!
Dialog.4=Si quieres cometer genocidio, el botín de los "monstruos poderosos" contribuirá lo suficiente con la economía para que puedo extorsionar más dinero de tus ciudadanos.
Dialog.5=¿Por qué necesitas tu dinero tan a menudo?
Dialog.6=Si me darías algo que puede almacenar tu dinero, como una alcancía, ¡ya no tendrías que hablar conmigo!
Dialog.7=Nunca cosecharás mi alma, ¿verdad?

-- Estado --
Status.StatusMessage=Pues, cobramos el alquiler por %1 cada %2 y estamos embolsando %3 cada hora. ¿Eso contesta la pregunta?
Status.Status=Estado

Status.ALotOfMoney=mucho dinero
Status.NotALotOfMoney=no mucho dinero
Status.Unknown=algo

-- Configuración --
Config.ClassicD=La experiencia clásica de Better Taxes con soporte básico para Calamity y Thorium.
Config.VanillaD=Devuelve el funcionamiento del recaudador de impuestos en Terraria vainilla.
Config.TaxRatesD=Conecta "statements" que representan progresión del juego con el alquilar por PNJ.
Config.IsFlexibleD=¿Otros mods pueden cambiar cosas en este fichero de configuración?
Config.AddCustomDialogD=¿Las líneas nuevas del diálogo deben estar incluido?
Config.EnableAutoCollectD=¿El recaudador de impuestos debe poner los impuestos en una Alcancía, Caja Fuerte o Forja del Defensor en su cuarto a medianoche?
Config.TimeBetweenPaychecksD=La cantidad de tiempo entre las actualizaciones del almacenamiento de impuestos.
Config.MoneyCapD=La cantidad de dinero que el recaudador de impuestos puede tener a la vez.
Config.ExpertModeBoostD=El valor por el cual multiplicar las tarifas de impuesto en un mundo experto.

Config.NoPerms=No puedes realizar esta acción porque no tienes el permiso "%1".

Config.Hour=hora
Config.Hours=horas
Config.Minute=minuto
Config.Minutes=minutos
Config.Second=segundo
Config.Seconds=segundos
Config.Tick=tic
Config.Unlimited=Ilimitado
Config.Disabled=Deshabilitado
2 changes: 1 addition & 1 deletion ModHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal static bool CheckForCalamity(bool setFlag = true)
}
catch (Exception ex)
{
BetterTaxes.Instance.Logger.Warn("Error when checking for calamity: " + ex.Message);
BetterTaxes.Instance.Logger.Warn("Error when checking for Calamity: " + ex.Message);
}

}
Expand Down
Loading

0 comments on commit d1e3d00

Please sign in to comment.