Commit 7b057aad authored by Francisco Iván García Torres's avatar Francisco Iván García Torres

Merge branch 'feature/jsonTranslator' into 'master'

add jsonTranslator

See merge request !1
parents 4094e0e3 cc49a6cf
......@@ -31,6 +31,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -41,8 +44,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="JsonTranslator.cs" />
<Compile Include="Traductor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Api.Business
{
public static class JsonTranslator
{
public static string TranslateJson(string collection, string languageCodeFrom, string languageCodeTo)
{
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(collection);
Dictionary<string, string> translatedCollection = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> item in values)
{
if (string.IsNullOrEmpty(item.Value) == false)
{
string translatedCollectionValue = Traductor.TranslateText(item.Value, languageCodeFrom, languageCodeTo);
translatedCollection.Add(item.Key, translatedCollectionValue);
}
}
return JsonConvert.SerializeObject(translatedCollection, Formatting.Indented);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net452" />
</packages>
\ No newline at end of file
using System.Web.Services;
using System.Collections.Generic;
using System.Web.Services;
namespace Api.Traductor
{
......@@ -19,7 +20,21 @@ namespace Api.Traductor
if (string.IsNullOrEmpty(langTo))
return "Seleccione un lenguaje de salida";
return Api.Business.Traductor.TranslateText(input,langFrom,langTo);
return Api.Business.Traductor.TranslateText(input, langFrom, langTo);
}
[WebMethod]
public string TranslateJson(string input, string langFrom, string langTo)
{
if (string.IsNullOrEmpty(input))
throw new System.Exception("El campo input no puede estar vacío");
if (string.IsNullOrEmpty(langFrom))
throw new System.Exception("El campo lenguaje origen no puede estar vacío");
if (string.IsNullOrEmpty(langTo))
throw new System.Exception("El campo lenguaje destino no puede estar vacío");
return Api.Business.JsonTranslator.TranslateJson(input, langFrom, langTo);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment