diff --git a/Helper/TranslationHelper.cs b/Helper/TranslationHelper.cs index 66c95ff..1950bb2 100644 --- a/Helper/TranslationHelper.cs +++ b/Helper/TranslationHelper.cs @@ -123,7 +123,9 @@ namespace CarCareTracker.Helper } public OperationResponse SaveTranslation(string userLanguage, Dictionary translations) { - if (userLanguage == "en_US") + bool create = bool.Parse(_config["LUBELOGGER_TRANSLATOR"] ?? "false"); + bool isDefaultLanguage = userLanguage == "en_US"; + if (isDefaultLanguage && !create) { return new OperationResponse { Success = false, Message = "The translation file name en_US is reserved." }; } @@ -135,7 +137,7 @@ namespace CarCareTracker.Helper { return new OperationResponse { Success = false, Message = "Translation has no data." }; } - var translationFilePath = _fileHelper.GetFullFilePath($"/translations/{userLanguage}.json", false); + var translationFilePath = isDefaultLanguage ? _fileHelper.GetFullFilePath($"/defaults/en_US.json") : _fileHelper.GetFullFilePath($"/translations/{userLanguage}.json", false); try { if (File.Exists(translationFilePath)) @@ -173,7 +175,13 @@ namespace CarCareTracker.Helper Directory.CreateDirectory(uploadDirectory); } var saveFilePath = _fileHelper.GetFullFilePath(tempFileName, false); - File.WriteAllText(saveFilePath, JsonSerializer.Serialize(translations)); + //standardize translation format for export only. + Dictionary sortedTranslations = new Dictionary(); + foreach (var translation in translations.OrderBy(x => x.Key)) + { + sortedTranslations.Add(translation.Key, translation.Value); + }; + File.WriteAllText(saveFilePath, JsonSerializer.Serialize(sortedTranslations, new JsonSerializerOptions { WriteIndented = true })); return tempFileName; } catch(Exception ex) diff --git a/Views/Home/_TranslationEditor.cshtml b/Views/Home/_TranslationEditor.cshtml index 40e75b1..cc9bc21 100644 --- a/Views/Home/_TranslationEditor.cshtml +++ b/Views/Home/_TranslationEditor.cshtml @@ -1,10 +1,12 @@ @using CarCareTracker.Helper @inject IConfigHelper config @inject ITranslationHelper translator +@inject IConfiguration serverConfig; @model Dictionary @{ var userConfig = config.GetUserConfig(User); var userLanguage = userConfig.UserLanguage; + bool showDelete = bool.Parse(serverConfig["LUBELOGGER_TRANSLATOR"] ?? "false"); }