Setting for choosing the language to use

- Download the appropriate language file regarding the language setting
- Stores language files in the "lang" subfolder
This commit is contained in:
ORelio 2014-02-01 14:57:31 +01:00
parent 86908c35a0
commit eef5e92af5
2 changed files with 28 additions and 23 deletions

View file

@ -95,29 +95,25 @@ namespace MinecraftClient
TranslationRules["commands.message.display.incoming"] = "§7%s whispers to you: %s"; TranslationRules["commands.message.display.incoming"] = "§7%s whispers to you: %s";
TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s"; TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s";
//Use translations from Minecraft assets if translation file is not found but a copy of the game is installed? //Language file in a subfolder, depending on the language setting
if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_GB.lang if (!System.IO.Directory.Exists("lang"))
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir)) System.IO.Directory.CreateDirectory("lang");
{
Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir;
Console.ForegroundColor = ConsoleColor.DarkGray;
ConsoleIO.WriteLine("Using en_GB.lang from your Minecraft directory.");
Console.ForegroundColor = ConsoleColor.Gray;
}
//Still not found? try downloading en_GB from Mojang's servers? string Language_File = "lang\\" + Settings.Language + ".lang";
if (!System.IO.File.Exists(Settings.TranslationsFile))
//File not found? Try downloading language file from Mojang's servers?
if (!System.IO.File.Exists(Language_File))
{ {
Console.ForegroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.DarkGray;
ConsoleIO.WriteLine("Downloading en_GB.lang from Mojang's servers..."); ConsoleIO.WriteLine("Downloading '" + Settings.Language + ".lang' from Mojang servers...");
try try
{ {
string assets_index = downloadString(Settings.TranslationsFile_Website_Index); string assets_index = downloadString(Settings.TranslationsFile_Website_Index);
string[] tmp = assets_index.Split(new string[] { "lang/en_GB.lang" }, StringSplitOptions.None); string[] tmp = assets_index.Split(new string[] { "lang/" + Settings.Language + ".lang" }, StringSplitOptions.None);
tmp = tmp[1].Split(new string[] { "hash\": \"" }, StringSplitOptions.None); tmp = tmp[1].Split(new string[] { "hash\": \"" }, StringSplitOptions.None);
string hash = tmp[1].Split('"')[0]; //Translations file identifier on Mojang's servers string hash = tmp[1].Split('"')[0]; //Translations file identifier on Mojang's servers
System.IO.File.WriteAllText(Settings.TranslationsFile, downloadString(Settings.TranslationsFile_Website_Download + '/' + hash.Substring(0, 2) + '/' + hash)); System.IO.File.WriteAllText(Language_File, downloadString(Settings.TranslationsFile_Website_Download + '/' + hash.Substring(0, 2) + '/' + hash));
ConsoleIO.WriteLine("Done. File saved as \"" + Settings.TranslationsFile + '"'); ConsoleIO.WriteLine("Done. File saved as '" + Language_File + '\'');
} }
catch catch
{ {
@ -126,10 +122,20 @@ namespace MinecraftClient
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
} }
//Load the external dictionnary of translation rules or display an error message //Download Failed? Defaulting to en_GB.lang if the game is installed
if (System.IO.File.Exists(Settings.TranslationsFile)) if (!System.IO.File.Exists(Language_File) //Try en_GB.lang
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir))
{ {
string[] translations = System.IO.File.ReadAllLines(Settings.TranslationsFile); Language_File = Settings.TranslationsFile_FromMCDir;
Console.ForegroundColor = ConsoleColor.DarkGray;
ConsoleIO.WriteLine("Defaulting to en_GB.lang from your Minecraft directory.");
Console.ForegroundColor = ConsoleColor.Gray;
}
//Load the external dictionnary of translation rules or display an error message
if (System.IO.File.Exists(Language_File))
{
string[] translations = System.IO.File.ReadAllLines(Language_File);
foreach (string line in translations) foreach (string line in translations)
{ {
if (line.Length > 0) if (line.Length > 0)
@ -149,8 +155,7 @@ namespace MinecraftClient
else //No external dictionnary found. else //No external dictionnary found.
{ {
Console.ForegroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.DarkGray;
ConsoleIO.WriteLine("Translations file not found: \"" + Settings.TranslationsFile + "\"" ConsoleIO.WriteLine("Translations file not found: \"" + Language_File + "\""
+ "\nYou can pick a translation file from .minecraft\\assets\\lang\\"
+ "\nSome messages won't be properly printed without this file."); + "\nSome messages won't be properly printed without this file.");
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
} }

View file

@ -27,8 +27,8 @@ namespace MinecraftClient
public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang
public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json"; public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json";
public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net"; public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net";
public static string TranslationsFile = "translations.lang";
public static string Bots_OwnersFile = "bot-owners.txt"; public static string Bots_OwnersFile = "bot-owners.txt";
public static string Language = "en_GB";
//AntiAFK Settings //AntiAFK Settings
public static bool AntiAFK_Enabled = false; public static bool AntiAFK_Enabled = false;
@ -121,7 +121,7 @@ namespace MinecraftClient
case "password": Password = argValue; break; case "password": Password = argValue; break;
case "serverip": ServerIP = argValue; break; case "serverip": ServerIP = argValue; break;
case "singlecommand": SingleCommand = argValue; break; case "singlecommand": SingleCommand = argValue; break;
case "translationsfile": TranslationsFile = argValue; break; case "language": Language = argValue; break;
case "botownersfile": Bots_OwnersFile = argValue; break; case "botownersfile": Bots_OwnersFile = argValue; break;
case "consoletitle": ConsoleTitle = argValue; break; case "consoletitle": ConsoleTitle = argValue; break;
} }
@ -212,7 +212,7 @@ namespace MinecraftClient
+ "\r\n" + "\r\n"
+ "#Advanced settings\r\n" + "#Advanced settings\r\n"
+ "\r\n" + "\r\n"
+ "translationsfile=translations.lang\r\n" + "language=en_GB\r\n"
+ "botownersfile=bot-owners.txt\r\n" + "botownersfile=bot-owners.txt\r\n"
+ "consoletitle=Minecraft Console Client - %username%\r\n" + "consoletitle=Minecraft Console Client - %username%\r\n"
+ "\r\n" + "\r\n"