├── .gitattributes ├── .gitignore ├── .vs └── restore.dg ├── LocalizationResourceGenerator.sln ├── README.md ├── samples └── LocalizationResourceGeneratorSample │ ├── LocalizationResourceGeneratorSample.csproj │ ├── Program.cs │ └── Resources │ ├── Resource.restext │ └── Resource.resx └── src └── LocalizationResourceGenerator ├── LocalizationResourceGenerator.csproj ├── Program.cs ├── ResourceFile.cs ├── ResourceFileType.cs ├── ResourceTextFile.cs └── Service References └── TranslatorService ├── ConnectedService.json └── Reference.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Make sh files under the build directory always have LF as line endings 8 | ############################################################################### 9 | build/*.sh eol=lf 10 | 11 | 12 | ############################################################################### 13 | # Set default behavior for command prompt diff. 14 | # 15 | # This is need for earlier builds of msysgit that does not have it on by 16 | # default for csharp files. 17 | # Note: This is only used by command line 18 | ############################################################################### 19 | #*.cs diff=csharp 20 | 21 | ############################################################################### 22 | # Set the merge driver for project and solution files 23 | # 24 | # Merging from the command prompt will add diff markers to the files if there 25 | # are conflicts (Merging from VS is not affected by the settings below, in VS 26 | # the diff markers are never inserted). Diff markers may cause the following 27 | # file extensions to fail to load in VS. An alternative would be to treat 28 | # these files as binary and thus will always conflict and require user 29 | # intervention with every merge. To do so, just uncomment the entries below 30 | ############################################################################### 31 | #*.sln merge=binary 32 | #*.csproj merge=binary 33 | #*.vbproj merge=binary 34 | #*.vcxproj merge=binary 35 | #*.vcproj merge=binary 36 | #*.dbproj merge=binary 37 | #*.fsproj merge=binary 38 | #*.lsproj merge=binary 39 | #*.wixproj merge=binary 40 | #*.modelproj merge=binary 41 | #*.sqlproj merge=binary 42 | #*.wwaproj merge=binary 43 | 44 | ############################################################################### 45 | # behavior for image files 46 | # 47 | # image files are treated as binary by default. 48 | ############################################################################### 49 | #*.jpg binary 50 | #*.png binary 51 | #*.gif binary 52 | 53 | ############################################################################### 54 | # diff behavior for common document formats 55 | # 56 | # Convert binary document formats to text before diffing them. This feature 57 | # is only available from the command line. Turn it on by uncommenting the 58 | # entries below. 59 | ############################################################################### 60 | #*.doc diff=astextplain 61 | #*.DOC diff=astextplain 62 | #*.docx diff=astextplain 63 | #*.DOCX diff=astextplain 64 | #*.dot diff=astextplain 65 | #*.DOT diff=astextplain 66 | #*.pdf diff=astextplain 67 | #*.PDF diff=astextplain 68 | #*.rtf diff=astextplain 69 | #*.RTF diff=astextplain 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | *.suo 4 | *.user 5 | _ReSharper.* 6 | *.DS_Store 7 | *.userprefs 8 | *.pidb 9 | *.vspx 10 | *.psess 11 | packages 12 | target 13 | artifacts 14 | StyleCop.Cache 15 | node_modules 16 | *.snk 17 | .nuget/NuGet.exe 18 | project.lock.json -------------------------------------------------------------------------------- /.vs/restore.dg: -------------------------------------------------------------------------------- 1 | #:C:\Users\Dell\Source\Repos\LocalizationResourceGenerator\samples\LocalizationResourceGeneratorSample\LocalizationResourceGeneratorSample.xproj 2 | -------------------------------------------------------------------------------- /LocalizationResourceGenerator.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2035 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalizationResourceGenerator", "src\LocalizationResourceGenerator\LocalizationResourceGenerator.csproj", "{7231AFFB-9B4F-4CD8-A995-8921B46062F3}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalizationResourceGeneratorSample", "samples\LocalizationResourceGeneratorSample\LocalizationResourceGeneratorSample.csproj", "{FE257DDC-2603-4FA3-A9C2-3326D23B35C8}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7231AFFB-9B4F-4CD8-A995-8921B46062F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {7231AFFB-9B4F-4CD8-A995-8921B46062F3}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {7231AFFB-9B4F-4CD8-A995-8921B46062F3}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {7231AFFB-9B4F-4CD8-A995-8921B46062F3}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {FE257DDC-2603-4FA3-A9C2-3326D23B35C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {FE257DDC-2603-4FA3-A9C2-3326D23B35C8}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {FE257DDC-2603-4FA3-A9C2-3326D23B35C8}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {FE257DDC-2603-4FA3-A9C2-3326D23B35C8}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {3F1003D3-7C88-4B39-B570-2EA59058943F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LocalizationResourceGenerator 2 | Localization Resource Generator & Translator CommandLine Tool for ASP.NET Core Application 3 | 4 | ### dotnet resgen 5 | 6 | `dotnet resgen` is a localization resource (resx) generator for the .NET Core applications. Also it translates the resource entries using Microsoft Translation APIs during the generation process. 7 | 8 | ### How To Install 9 | 10 | 1. Run the following command: `dotnet publish -c Debug -r {runtime identifier}` 11 | 2. Add the binaries folder path - which is located in `LocalizationResourceGenerator\src\LocalizationResourceGenerator\bin\Debug\{netcoreapp version}\{runtime identifier}` - to the System PATH. 12 | 13 | ### How To Use 14 | 15 | dotnet resgen [arguments] [options] 16 | 17 | Arguments: 18 | cultures List of cultures, that the command will generate a resource file(s) for each one for them 19 | 20 | Options: 21 | -h|--help Show help information 22 | --default The default culture that the command will use it to translate from 23 | -t|--type The type of the resource file [resx|restext] 24 | 25 | Here is a few examples: 26 | 27 | | Command | Description | 28 | | -----------------------------------| -------------------------------------------------------- | 29 | | dotnet resgen fr | Generates a `fr.resx` resource file from `.resx` file with `en` as default culture | 30 | | dotnet resgen fr es | Generates a `fr.resx` and `es.resx` resource files from `.resx` file with `en` as default culture | 31 | | dotnet resgen fr --default es | Generates a `fr.resx` resource file from `.resx` file with Spanish as default culture | 32 | | dotnet resgen fr -t restext | Generates a `fr.resx` resource file from `.restext` file with Spanish as default culture | 33 | 34 | There are few steps you should consider before using the `dotnet resgen` command: 35 | - Create your default resource file **without append the culture name** in your resource directory 36 | - Go to the resource directory using command line 37 | - Run `dotnet resgen` command -------------------------------------------------------------------------------- /samples/LocalizationResourceGeneratorSample/LocalizationResourceGeneratorSample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1 5 | LocalizationResourceGeneratorSample 6 | Exe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/LocalizationResourceGeneratorSample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace LocalizationResourceGeneratorSample 7 | { 8 | public class Program 9 | { 10 | public static void Main(string[] args) 11 | { 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /samples/LocalizationResourceGeneratorSample/Resources/Resource.restext: -------------------------------------------------------------------------------- 1 | # Resource in Text File 2 | 3 | Greeting = Hello -------------------------------------------------------------------------------- /samples/LocalizationResourceGeneratorSample/Resources/Resource.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Hello 122 | 123 | -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/LocalizationResourceGenerator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.1 5 | dotnet-resgen 6 | Exe 7 | 2.1.5 8 | win10-x64 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.IO; 5 | using System.Threading.Tasks; 6 | using System.Xml.Linq; 7 | using McMaster.Extensions.CommandLineUtils; 8 | using TranslatorService; 9 | using static TranslatorService.LanguageServiceClient; 10 | 11 | namespace LocalizationResourceGenerator 12 | { 13 | public class Program 14 | { 15 | private static readonly string _appKey = "6CE9C85A41571C050C379F60DA173D286384E0F2"; 16 | private static readonly string _defaultCulture = "en"; 17 | private static readonly string _defaultResourceType = "resx"; 18 | private static readonly LanguageServiceClient client = new LanguageServiceClient(EndpointConfiguration.BasicHttpBinding_LanguageService); 19 | 20 | public static int Main(string[] args) 21 | => CommandLineApplication.Execute(args); 22 | 23 | [Argument(0, Name = "cultures", Description = "List of cultures, that command will generate a resource file(s) for each one for them")] 24 | [Required] 25 | public IList Cultures { get; } 26 | 27 | [Option("--default ", LongName = "default", Description = "The default culture that the command will use it to translate from")] 28 | public string DefaultCulture { get; } 29 | 30 | [Option("-t|--type ", ShortName ="t", LongName = "type", Description = "The type of the resource file [resx|restext]")] 31 | public string ResourceType { get; } 32 | 33 | private async Task OnExecuteAsync() 34 | { 35 | const string resourceExtension = "resx"; 36 | var defaultCulture = DefaultCulture ?? _defaultCulture; 37 | var resourceType = (ResourceFileType)Enum.Parse(typeof(ResourceFileType), ResourceType ?? _defaultResourceType, true); 38 | 39 | switch (resourceType) 40 | { 41 | case ResourceFileType.Resx: 42 | case ResourceFileType.Restext: 43 | var currentDirectory = Directory.GetCurrentDirectory(); 44 | XDocument doc = null; 45 | 46 | foreach (var filePath in Directory.GetFiles(currentDirectory, "*." + resourceType.ToString().ToLower())) 47 | { 48 | var file = new FileInfo(filePath); 49 | 50 | if (!Path.GetFileNameWithoutExtension(file.Name).Contains(".")) 51 | { 52 | foreach (var culture in Cultures) 53 | { 54 | var resourceFileName = string.Join(".", Path.GetFileNameWithoutExtension(file.Name), culture, resourceExtension); 55 | var resourcePath = Path.Combine(currentDirectory, resourceFileName); 56 | 57 | if (resourceType == ResourceFileType.Resx) 58 | { 59 | File.Copy(file.FullName, resourcePath, true); 60 | doc = XDocument.Load(resourcePath); 61 | } 62 | else 63 | { 64 | doc = ResourceTextFile.Load(file.OpenRead()); 65 | } 66 | 67 | foreach (var element in doc.Root.Elements("data")) 68 | { 69 | var key = element.Element("value").Value; 70 | var result = await client.TranslateAsync(_appKey, key.ToString(), defaultCulture, culture); 71 | 72 | element.SetElementValue("value", result); 73 | } 74 | 75 | using (var stream = new FileStream(resourcePath, FileMode.OpenOrCreate, FileAccess.Write)) 76 | { 77 | doc.Save(stream); 78 | } 79 | } 80 | } 81 | } 82 | 83 | return 0; 84 | default: 85 | throw new NotSupportedException($"Unsupported resource file with extension {resourceType}."); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/ResourceFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace LocalizationResourceGenerator 5 | { 6 | internal class ResourceFile 7 | { 8 | public ResourceFile(FileInfo file, ResourceFileType type) 9 | { 10 | File = file; 11 | Type = type; 12 | } 13 | 14 | public FileInfo File { get; } 15 | public ResourceFileType Type { get; } 16 | 17 | public static ResourceFile Create(string fileName) 18 | { 19 | var fileInfo = new FileInfo(fileName); 20 | ResourceFileType type; 21 | var extension = fileInfo.Extension.ToLowerInvariant(); 22 | 23 | switch (extension) 24 | { 25 | case ".resx": 26 | type = ResourceFileType.Resx; 27 | break; 28 | case ".restext": 29 | type = ResourceFileType.Restext; 30 | break; 31 | default: 32 | throw new NotSupportedException($"Unsupported resource file with extension '{extension}'."); 33 | } 34 | 35 | return new ResourceFile(fileInfo, type); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/ResourceFileType.cs: -------------------------------------------------------------------------------- 1 | namespace LocalizationResourceGenerator 2 | { 3 | public enum ResourceFileType 4 | { 5 | Resx, 6 | Restext 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/ResourceTextFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Xml.Linq; 5 | 6 | namespace LocalizationResourceGenerator 7 | { 8 | public class ResourceTextFile 9 | { 10 | private static string _resxFileContent = @" 11 | 12 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | text/microsoft-resx 119 | 120 | 121 | 2.0 122 | 123 | 124 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 125 | 126 | 127 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 128 | 129 | "; 130 | 131 | private static Dictionary Data { get; set; } 132 | 133 | public static XDocument Load(Stream stream) 134 | { 135 | var data = new Dictionary(StringComparer.OrdinalIgnoreCase); 136 | 137 | using (var reader = new StreamReader(stream)) 138 | { 139 | while (reader.Peek() != -1) 140 | { 141 | var rawLine = reader.ReadLine(); 142 | var line = rawLine.Trim(); 143 | 144 | // Ignore blank lines 145 | if (string.IsNullOrWhiteSpace(line)) 146 | { 147 | continue; 148 | } 149 | // Ignore comments 150 | if (line[0] == ';' || line[0] == '#' || line[0] == '/') 151 | { 152 | continue; 153 | } 154 | // Ignore sections 155 | if (line[0] == '[' && line[line.Length - 1] == ']') 156 | { 157 | continue; 158 | } 159 | 160 | // key = value OR "value" 161 | int separator = line.IndexOf('='); 162 | if (separator <0) 163 | { 164 | throw new FormatException("Unrecognized line format"); 165 | } 166 | 167 | string key = line.Substring(0, separator).Trim(); 168 | string value = line.Substring(separator + 1).Trim(); 169 | 170 | // Remove quotes 171 | if (value.Length> 1 && value[0] == '"' && value[value.Length - 1] == '"') 172 | { 173 | value = value.Substring(1, value.Length - 2); 174 | } 175 | 176 | if (data.ContainsKey(key)) 177 | { 178 | throw new FormatException("Key is duplicated"); 179 | } 180 | 181 | data[key] = value; 182 | } 183 | } 184 | 185 | Data = data; 186 | 187 | return GenerateResxFile(); 188 | } 189 | 190 | private static XDocument GenerateResxFile() 191 | { 192 | var doc = XDocument.Parse(_resxFileContent); 193 | 194 | foreach (var item in Data) 195 | { 196 | var node = new XElement("data"); 197 | 198 | node.SetAttributeValue("name", item.Key); 199 | node.SetAttributeValue(XNamespace.Xmlns + "space","preserve"); 200 | node.SetElementValue("value", item.Value); 201 | doc.Root.Add(node); 202 | } 203 | 204 | return doc; 205 | } 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/Service References/TranslatorService/ConnectedService.json: -------------------------------------------------------------------------------- 1 | { 2 | "ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf", 3 | "Version": "0.3.20722.0", 4 | "GettingStartedDocument": { 5 | "Uri": "http://go.microsoft.com/fwlink/?LinkId=703956" 6 | } 7 | } -------------------------------------------------------------------------------- /src/LocalizationResourceGenerator/Service References/TranslatorService/Reference.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace TranslatorService 11 | { 12 | 13 | 14 | [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")] 15 | [System.ServiceModel.ServiceContractAttribute(Namespace="http://api.microsofttranslator.com/v1/soap.svc", ConfigurationName="TranslatorService.LanguageService")] 16 | public interface LanguageService 17 | { 18 | 19 | [System.ServiceModel.OperationContractAttribute(Action="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/GetLanguages", ReplyAction="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/GetLanguagesRespon" + 20 | "se")] 21 | System.Threading.Tasks.Task GetLanguagesAsync(string appId); 22 | 23 | [System.ServiceModel.OperationContractAttribute(Action="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/GetLanguageNames", ReplyAction="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/GetLanguageNamesRe" + 24 | "sponse")] 25 | System.Threading.Tasks.Task GetLanguageNamesAsync(string appId, string locale); 26 | 27 | [System.ServiceModel.OperationContractAttribute(Action="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/Detect", ReplyAction="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/DetectResponse")] 28 | System.Threading.Tasks.Task DetectAsync(string appId, string text); 29 | 30 | [System.ServiceModel.OperationContractAttribute(Action="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/Translate", ReplyAction="http://api.microsofttranslator.com/v1/soap.svc/LanguageService/TranslateResponse")] 31 | System.Threading.Tasks.Task TranslateAsync(string appId, string text, string from, string to); 32 | } 33 | 34 | [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")] 35 | public interface LanguageServiceChannel : TranslatorService.LanguageService, System.ServiceModel.IClientChannel 36 | { 37 | } 38 | 39 | [System.Diagnostics.DebuggerStepThroughAttribute()] 40 | [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")] 41 | public partial class LanguageServiceClient : System.ServiceModel.ClientBase, TranslatorService.LanguageService 42 | { 43 | 44 | /// 45 | /// Implement this partial method to configure the service endpoint. 46 | /// 47 | /// The endpoint to configure 48 | /// The client credentials 49 | static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); 50 | 51 | public LanguageServiceClient(EndpointConfiguration endpointConfiguration) : 52 | base(LanguageServiceClient.GetBindingForEndpoint(endpointConfiguration), LanguageServiceClient.GetEndpointAddress(endpointConfiguration)) 53 | { 54 | this.Endpoint.Name = endpointConfiguration.ToString(); 55 | ConfigureEndpoint(this.Endpoint, this.ClientCredentials); 56 | } 57 | 58 | public LanguageServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : 59 | base(LanguageServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress)) 60 | { 61 | this.Endpoint.Name = endpointConfiguration.ToString(); 62 | ConfigureEndpoint(this.Endpoint, this.ClientCredentials); 63 | } 64 | 65 | public LanguageServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : 66 | base(LanguageServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) 67 | { 68 | this.Endpoint.Name = endpointConfiguration.ToString(); 69 | ConfigureEndpoint(this.Endpoint, this.ClientCredentials); 70 | } 71 | 72 | public LanguageServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 73 | base(binding, remoteAddress) 74 | { 75 | } 76 | 77 | public System.Threading.Tasks.Task GetLanguagesAsync(string appId) 78 | { 79 | return base.Channel.GetLanguagesAsync(appId); 80 | } 81 | 82 | public System.Threading.Tasks.Task GetLanguageNamesAsync(string appId, string locale) 83 | { 84 | return base.Channel.GetLanguageNamesAsync(appId, locale); 85 | } 86 | 87 | public System.Threading.Tasks.Task DetectAsync(string appId, string text) 88 | { 89 | return base.Channel.DetectAsync(appId, text); 90 | } 91 | 92 | public System.Threading.Tasks.Task TranslateAsync(string appId, string text, string from, string to) 93 | { 94 | return base.Channel.TranslateAsync(appId, text, from, to); 95 | } 96 | 97 | public virtual System.Threading.Tasks.Task OpenAsync() 98 | { 99 | return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndOpen)); 100 | } 101 | 102 | public virtual System.Threading.Tasks.Task CloseAsync() 103 | { 104 | return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndClose)); 105 | } 106 | 107 | private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) 108 | { 109 | if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_LanguageService)) 110 | { 111 | System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(); 112 | result.MaxBufferSize = int.MaxValue; 113 | result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; 114 | result.MaxReceivedMessageSize = int.MaxValue; 115 | result.AllowCookies = true; 116 | return result; 117 | } 118 | if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_LanguageService1)) 119 | { 120 | System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(); 121 | result.MaxBufferSize = int.MaxValue; 122 | result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; 123 | result.MaxReceivedMessageSize = int.MaxValue; 124 | result.AllowCookies = true; 125 | return result; 126 | } 127 | throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); 128 | } 129 | 130 | private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) 131 | { 132 | if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_LanguageService)) 133 | { 134 | return new System.ServiceModel.EndpointAddress("http://api.microsofttranslator.com/V1/soap.svc"); 135 | } 136 | if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_LanguageService1)) 137 | { 138 | return new System.ServiceModel.EndpointAddress("http://api.microsofttranslator.com/V1/soap.svc"); 139 | } 140 | throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); 141 | } 142 | 143 | public enum EndpointConfiguration 144 | { 145 | 146 | BasicHttpBinding_LanguageService, 147 | 148 | BasicHttpBinding_LanguageService1, 149 | } 150 | } 151 | } 152 | --------------------------------------------------------------------------------