85 lines
3.3 KiB
C#
85 lines
3.3 KiB
C#
using OnlyOneAccessTemplate.Services.OnlyOneAccessTemplate.Services;
|
|
|
|
namespace OnlyOneAccessTemplate.Services
|
|
{
|
|
public class TextCaseConverterService : BaseConverterService
|
|
{
|
|
public override string ConverterType => "text-case";
|
|
public override string ConverterName => "Text Case Converter";
|
|
|
|
public TextCaseConverterService(ILogger<TextCaseConverterService> logger, IConfiguration configuration)
|
|
: base(logger, configuration) { }
|
|
|
|
public override async Task<ConversionResult> ConvertAsync(ConversionRequest request)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(request.TextInput))
|
|
{
|
|
return new ConversionResult(false, ErrorMessage: "Texto não fornecido");
|
|
}
|
|
|
|
var caseType = request.Options?.GetValueOrDefault("caseType", "upper")?.ToString() ?? "upper";
|
|
|
|
var result = caseType switch
|
|
{
|
|
"upper" => request.TextInput.ToUpperInvariant(),
|
|
"lower" => request.TextInput.ToLowerInvariant(),
|
|
"title" => System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(request.TextInput.ToLower()),
|
|
"sentence" => char.ToUpper(request.TextInput[0]) + request.TextInput.Substring(1).ToLower(),
|
|
_ => request.TextInput
|
|
};
|
|
|
|
return new ConversionResult(true, OutputText: result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Erro na conversão de texto");
|
|
return new ConversionResult(false, ErrorMessage: "Erro ao converter texto");
|
|
}
|
|
}
|
|
|
|
public override ConverterConfiguration GetConfiguration(string language)
|
|
{
|
|
var texts = GetLocalizedTexts(language);
|
|
texts["ConverterTitle"] = language switch
|
|
{
|
|
"en" => "TEXT CASE CONVERTER",
|
|
"es" => "CONVERTIDOR DE MAYÚSCULAS Y MINÚSCULAS",
|
|
_ => "CONVERSOR DE MAIÚSCULAS E MINÚSCULAS"
|
|
};
|
|
|
|
texts["ConverterDescription"] = language switch
|
|
{
|
|
"en" => "Convert text between uppercase, lowercase, title case and sentence case",
|
|
"es" => "Convierte texto entre mayúsculas, minúsculas, título y oración",
|
|
_ => "Converta texto entre maiúsculas, minúsculas, título e primeira maiúscula"
|
|
};
|
|
|
|
texts["InputPlaceholder"] = language switch
|
|
{
|
|
"en" => "Enter your text here...",
|
|
"es" => "Ingresa tu texto aquí...",
|
|
_ => "Digite seu texto aqui..."
|
|
};
|
|
|
|
texts["OutputPlaceholder"] = language switch
|
|
{
|
|
"en" => "Converted text will appear here...",
|
|
"es" => "El texto convertido aparecerá aquí...",
|
|
_ => "O texto convertido aparecerá aqui..."
|
|
};
|
|
|
|
return new ConverterConfiguration
|
|
{
|
|
ConverterType = "text",
|
|
OutputType = "text",
|
|
HasAdvancedOptions = true,
|
|
AllowShare = true,
|
|
LocalizedTexts = texts
|
|
};
|
|
}
|
|
}
|
|
|
|
}
|