2018-04-22 15:04:18 -05:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.Localization
|
|
|
|
|
{
|
|
|
|
|
public class Configure
|
|
|
|
|
{
|
|
|
|
|
public static void Initialize()
|
|
|
|
|
{
|
2018-04-26 19:19:42 -05:00
|
|
|
|
string currentLocale = Program.ServerManager.GetApplicationSettings().Configuration()?.CustomLocale ??
|
|
|
|
|
CultureInfo.CurrentCulture?.Name?.Substring(0, 2);
|
2018-04-26 15:26:03 -05:00
|
|
|
|
|
|
|
|
|
if (currentLocale == null)
|
|
|
|
|
throw new Exception("Computer CurrentCulture does not exist");
|
2018-04-23 00:43:48 -05:00
|
|
|
|
#if DEBUG
|
2018-04-23 16:03:50 -05:00
|
|
|
|
// currentLocal = "ru-RU";
|
2018-04-23 00:43:48 -05:00
|
|
|
|
#endif
|
2018-04-24 17:01:27 -05:00
|
|
|
|
string localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.{currentLocale}-{currentLocale.ToUpper()}.json";
|
2018-04-22 15:04:18 -05:00
|
|
|
|
string localizationContents;
|
|
|
|
|
|
|
|
|
|
if (File.Exists(localizationFile))
|
|
|
|
|
{
|
2018-04-24 17:01:27 -05:00
|
|
|
|
localizationContents = File.ReadAllText(localizationFile, Encoding.UTF8);
|
2018-04-22 15:04:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-26 15:26:03 -05:00
|
|
|
|
localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.en-EN.json";
|
2018-04-23 00:43:48 -05:00
|
|
|
|
localizationContents = File.ReadAllText(localizationFile, Encoding.UTF8);
|
2018-04-22 15:04:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 15:26:03 -05:00
|
|
|
|
if (localizationContents.Length < 1)
|
|
|
|
|
throw new Exception($"Localization file {localizationFile} does not exist");
|
2018-04-22 15:04:18 -05:00
|
|
|
|
Utilities.CurrentLocalization = Newtonsoft.Json.JsonConvert.DeserializeObject<SharedLibraryCore.Localization.Layout>(localizationContents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|