OSDN Git Service

シンプルな型名を使用する (IDE0049)
[opentween/open-tween.git] / OpenTween / Bing.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2011      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
9 // 
10 // This file is part of OpenTween.
11 // 
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 // 
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details. 
21 // 
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 using System;
28 using System.Collections.Generic;
29 using System.Net.Http;
30 using System.Text;
31 using System.Threading;
32 using System.Threading.Tasks;
33 using OpenTween.Api;
34 using OpenTween.Connection;
35
36 namespace OpenTween
37 {
38     public class Bing
39     {
40         private static readonly List<string> LanguageTable = new List<string>
41         {
42             "af",
43             "sq",
44             "ar-sa",
45             "ar-iq",
46             "ar-eg",
47             "ar-ly",
48             "ar-dz",
49             "ar-ma",
50             "ar-tn",
51             "ar-om",
52             "ar-ye",
53             "ar-sy",
54             "ar-jo",
55             "ar-lb",
56             "ar-kw",
57             "ar-ae",
58             "ar-bh",
59             "ar-qa",
60             "eu",
61             "bg",
62             "be",
63             "ca",
64             "zh-tw",
65             "zh-cn",
66             "zh-hk",
67             "zh-sg",
68             "hr",
69             "cs",
70             "da",
71             "nl",
72             "nl-be",
73             "en",
74             "en-us",
75             "en-gb",
76             "en-au",
77             "en-ca",
78             "en-nz",
79             "en-ie",
80             "en-za",
81             "en-jm",
82             "en",
83             "en-bz",
84             "en-tt",
85             "et",
86             "fo",
87             "fa",
88             "fi",
89             "fr",
90             "fr-be",
91             "fr-ca",
92             "fr-ch",
93             "fr-lu",
94             "gd",
95             "ga",
96             "de",
97             "de-ch",
98             "de-at",
99             "de-lu",
100             "de-li",
101             "el",
102             "he",
103             "hi",
104             "hu",
105             "is",
106             "id",
107             "it",
108             "it-ch",
109             "ja",
110             "ko",
111             "ko",
112             "lv",
113             "lt",
114             "mk",
115             "ms",
116             "mt",
117             "no",
118             "no",
119             "pl",
120             "pt-br",
121             "pt",
122             "rm",
123             "ro",
124             "ro-mo",
125             "ru",
126             "ru-mo",
127             "sz",
128             "sr",
129             "sr",
130             "sk",
131             "sl",
132             "sb",
133             "es",
134             "es-mx",
135             "es-gt",
136             "es-cr",
137             "es-pa",
138             "es-do",
139             "es-ve",
140             "es-co",
141             "es-pe",
142             "es-ar",
143             "es-ec",
144             "es-cl",
145             "es-uy",
146             "es-py",
147             "es-bo",
148             "es-sv",
149             "es-hn",
150             "es-ni",
151             "es-pr",
152             "sx",
153             "sv",
154             "sv-fi",
155             "th",
156             "ts",
157             "tn",
158             "tr",
159             "uk",
160             "ur",
161             "ve",
162             "vi",
163             "xh",
164             "ji",
165             "zu",
166         };
167
168         private readonly MicrosoftTranslatorApi translatorApi;
169
170         public Bing()
171             : this(null)
172         {
173         }
174
175         public Bing(HttpClient http)
176             => this.translatorApi = new MicrosoftTranslatorApi(http);
177
178         /// <summary>
179         /// Microsoft Translator API を使用した翻訳を非同期に行います
180         /// </summary>
181         /// <exception cref="HttpRequestException"/>
182         public async Task<string> TranslateAsync(string text, string langFrom, string langTo)
183             => await this.translatorApi.TranslateAsync(text, langTo, langFrom)
184                 .ConfigureAwait(false);
185
186         public static string GetLanguageEnumFromIndex(int index)
187             => LanguageTable[index];
188
189         public static int GetIndexFromLanguageEnum(string lang)
190             => LanguageTable.IndexOf(lang);
191     }
192 }