This commit is contained in:
2020-06-05 19:25:00 +00:00
parent 3111f7fdb7
commit ac3bfb50bf
3 changed files with 135 additions and 227 deletions

View File

@@ -28,7 +28,7 @@ namespace AyaNova.Biz
u.Password = Hasher.hash(u.Salt, "l3tm3in");
u.Roles = AuthorizationRoles.All;//AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull;
u.UserType = UserType.Administrator;
u.UserOptions = new UserOptions();
u.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;//Ensure primeTranslations is called first
@@ -59,38 +59,43 @@ namespace AyaNova.Biz
await ImportTranslation(ResourceFolderPath, "fr");
await ImportTranslation(ResourceFolderPath, "de");
//Ensure Translations are present, not missing any keys and that there is a server default translation that exists
TranslationBiz lb = TranslationBiz.GetBiz(ServiceProviderProvider.DBContext);
await lb.ValidateTranslationsAsync();
//Ensure Translations are present, not missing any keys and that there is a server default translation that exists
using (AyContext ct = ServiceProviderProvider.DBContext)
{
TranslationBiz lb = TranslationBiz.GetBiz(ct);
await lb.ValidateTranslationsAsync();
}
}
private static async Task ImportTranslation(string resourceFolderPath, string translationCode)
{
AyContext ct = ServiceProviderProvider.DBContext;
var TranslationPath = Path.Combine(resourceFolderPath, $"{translationCode}.json");
if (!File.Exists(TranslationPath))
using (AyContext ct = ServiceProviderProvider.DBContext)
{
throw new System.Exception($"E1013: stock translation file \"{translationCode}\" not found where expected: \"{TranslationPath}\", installation damaged?");
var TranslationPath = Path.Combine(resourceFolderPath, $"{translationCode}.json");
if (!File.Exists(TranslationPath))
{
throw new System.Exception($"E1013: stock translation file \"{translationCode}\" not found where expected: \"{TranslationPath}\", installation damaged?");
}
JObject o = JObject.Parse(await File.ReadAllTextAsync(TranslationPath));
Translation l = new Translation();
l.Name = translationCode;
l.Stock = true;
l.CjkIndex = false;
foreach (JToken t in o.Children())
{
var key = t.Path;
var display = t.First.Value<string>();
l.TranslationItems.Add(new TranslationItem() { Key = key, Display = display });
}
await ct.Translation.AddAsync(l);
await ct.SaveChangesAsync();
}
JObject o = JObject.Parse(await File.ReadAllTextAsync(TranslationPath));
Translation l = new Translation();
l.Name = translationCode;
l.Stock = true;
l.CjkIndex = false;
foreach (JToken t in o.Children())
{
var key = t.Path;
var display = t.First.Value<string>();
l.TranslationItems.Add(new TranslationItem() { Key = key, Display = display });
}
await ct.Translation.AddAsync(l);
await ct.SaveChangesAsync();
}