2018-04-22 16:04:18 -04: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-24 18:01:27 -04:00
|
|
|
|
string currentLocale = Program.ServerManager.GetApplicationSettings().Configuration().CustomLocale ??
|
2018-04-26 16:26:03 -04:00
|
|
|
|
CultureInfo.CurrentCulture.Name?.Substring(0, 2);
|
|
|
|
|
|
|
|
|
|
if (currentLocale == null)
|
|
|
|
|
throw new Exception("Computer CurrentCulture does not exist");
|
2018-04-23 01:43:48 -04:00
|
|
|
|
#if DEBUG
|
2018-04-23 17:03:50 -04:00
|
|
|
|
// currentLocal = "ru-RU";
|
2018-04-23 01:43:48 -04:00
|
|
|
|
#endif
|
2018-04-24 18:01:27 -04:00
|
|
|
|
string localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.{currentLocale}-{currentLocale.ToUpper()}.json";
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string localizationContents;
|
|
|
|
|
|
|
|
|
|
if (File.Exists(localizationFile))
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
localizationContents = File.ReadAllText(localizationFile, Encoding.UTF8);
|
2018-04-22 16:04:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-26 16:26:03 -04:00
|
|
|
|
localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.en-EN.json";
|
2018-04-23 01:43:48 -04:00
|
|
|
|
localizationContents = File.ReadAllText(localizationFile, Encoding.UTF8);
|
2018-04-22 16:04:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 16:26:03 -04:00
|
|
|
|
if (localizationContents.Length < 1)
|
|
|
|
|
throw new Exception($"Localization file {localizationFile} does not exist");
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Utilities.CurrentLocalization = Newtonsoft.Json.JsonConvert.DeserializeObject<SharedLibraryCore.Localization.Layout>(localizationContents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|