mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-11 04:37:03 -06:00
see requirements for 706
This commit is contained in:
parent
5411d4152c
commit
9cd8030808
@ -123,7 +123,9 @@ namespace CarCareTracker.Helper
|
|||||||
}
|
}
|
||||||
public OperationResponse SaveTranslation(string userLanguage, Dictionary<string, string> translations)
|
public OperationResponse SaveTranslation(string userLanguage, Dictionary<string, string> 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." };
|
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." };
|
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
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(translationFilePath))
|
if (File.Exists(translationFilePath))
|
||||||
@ -173,7 +175,13 @@ namespace CarCareTracker.Helper
|
|||||||
Directory.CreateDirectory(uploadDirectory);
|
Directory.CreateDirectory(uploadDirectory);
|
||||||
}
|
}
|
||||||
var saveFilePath = _fileHelper.GetFullFilePath(tempFileName, false);
|
var saveFilePath = _fileHelper.GetFullFilePath(tempFileName, false);
|
||||||
File.WriteAllText(saveFilePath, JsonSerializer.Serialize(translations));
|
//standardize translation format for export only.
|
||||||
|
Dictionary<string, string> sortedTranslations = new Dictionary<string, string>();
|
||||||
|
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;
|
return tempFileName;
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
@using CarCareTracker.Helper
|
@using CarCareTracker.Helper
|
||||||
@inject IConfigHelper config
|
@inject IConfigHelper config
|
||||||
@inject ITranslationHelper translator
|
@inject ITranslationHelper translator
|
||||||
|
@inject IConfiguration serverConfig;
|
||||||
@model Dictionary<string, string>
|
@model Dictionary<string, string>
|
||||||
@{
|
@{
|
||||||
var userConfig = config.GetUserConfig(User);
|
var userConfig = config.GetUserConfig(User);
|
||||||
var userLanguage = userConfig.UserLanguage;
|
var userLanguage = userConfig.UserLanguage;
|
||||||
|
bool showDelete = bool.Parse(serverConfig["LUBELOGGER_TRANSLATOR"] ?? "false");
|
||||||
}
|
}
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title" id="translationEditorModalLabel">@translator.Translate(userLanguage, "Translation Editor")</h5>
|
<h5 class="modal-title" id="translationEditorModalLabel">@translator.Translate(userLanguage, "Translation Editor")</h5>
|
||||||
@ -15,8 +17,15 @@
|
|||||||
<div class="form-group" style="max-height:50vh; overflow-x:hidden; overflow-y:scroll;">
|
<div class="form-group" style="max-height:50vh; overflow-x:hidden; overflow-y:scroll;">
|
||||||
@foreach(var translation in Model)
|
@foreach(var translation in Model)
|
||||||
{
|
{
|
||||||
<div class="row translation-keyvalue mb-2">
|
<div class="row translation-keyvalue mb-2 align-items-center">
|
||||||
<div class="col-md-6 col-12 translation-key">@translation.Key.Replace("_", " ")</div>
|
@if (showDelete)
|
||||||
|
{
|
||||||
|
<div class="col-md-1 col-1 translation-delete"><button onclick="deleteTranslationKey(this)" class="btn text-danger btn-sm"><i class="bi bi-x-lg"></i></button></div>
|
||||||
|
<div class="col-md-5 col-11 translation-key">@translation.Key.Replace("_", " ")</div>
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
<div class="col-md-6 col-12 translation-key">@translation.Key.Replace("_", " ")</div>
|
||||||
|
}
|
||||||
<div class="col-md-6 col-12 translation-value">
|
<div class="col-md-6 col-12 translation-value">
|
||||||
<textarea style="height:100%;width:98%;" class="form-control" placeholder="@translation.Value">@translation.Value</textarea>
|
<textarea style="height:100%;width:98%;" class="form-control" placeholder="@translation.Value">@translation.Value</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -189,6 +189,7 @@ function saveTranslation() {
|
|||||||
errorToast(genericErrorMessage());
|
errorToast(genericErrorMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var userCanDelete = $(".translation-delete").length > 0;
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Save Translation',
|
title: 'Save Translation',
|
||||||
html: `
|
html: `
|
||||||
@ -200,7 +201,7 @@ function saveTranslation() {
|
|||||||
const translationFileName = $("#translationFileName").val();
|
const translationFileName = $("#translationFileName").val();
|
||||||
if (!translationFileName || translationFileName.trim() == '') {
|
if (!translationFileName || translationFileName.trim() == '') {
|
||||||
Swal.showValidationMessage(`Please enter a valid file name`);
|
Swal.showValidationMessage(`Please enter a valid file name`);
|
||||||
} else if (translationFileName.trim() == 'en_US') {
|
} else if (translationFileName.trim() == 'en_US' && !userCanDelete) {
|
||||||
Swal.showValidationMessage(`en_US is reserved, please enter a different name`);
|
Swal.showValidationMessage(`en_US is reserved, please enter a different name`);
|
||||||
}
|
}
|
||||||
return { translationFileName }
|
return { translationFileName }
|
||||||
@ -270,6 +271,9 @@ function downloadAllTranslations() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function deleteTranslationKey(e) {
|
||||||
|
$(e).parent().parent().remove();
|
||||||
|
}
|
||||||
//tabs reorder
|
//tabs reorder
|
||||||
function showTabReorderModal() {
|
function showTabReorderModal() {
|
||||||
//reorder the list items based on the CSS attribute
|
//reorder the list items based on the CSS attribute
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user