Kaynağa Gözat

add google api support lang

姜青儀 1 yıl önce
ebeveyn
işleme
b7d075ca27
3 değiştirilmiş dosya ile 207 ekleme ve 1 silme
  1. 19 0
      GoogleCloud/Data/Lang.cs
  2. 187 1
      GoogleCloud/GoogleCloud.cs
  3. 1 0
      KdanCommon.csproj

+ 19 - 0
GoogleCloud/Data/Lang.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace KdanCommon.GoogleCloud.Data
+{
+    public class Lang
+    {
+        public string ISOCode { get; private set; }   // two letter ISO 639 code, allow exceptions :zh-CN, zh-TW
+        public string EnglishName { get; private set; }
+        public Lang(string name, string code)
+        {
+            ISOCode = code;
+            EnglishName = name;
+        }
+    }
+}

+ 187 - 1
GoogleCloud/GoogleCloud.cs

@@ -1,8 +1,10 @@
-using KdanCommon.GoogleCloud.Data.Vision;
+using KdanCommon.GoogleCloud.Data;
+using KdanCommon.GoogleCloud.Data.Vision;
 using KdanCommon.Helpers;
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Net.Http;
 using System.Text;
@@ -61,5 +63,189 @@ namespace KdanCommon.GoogleCloud
             }
             return response;
         }
+
+        // source : https://cloud.google.com/vision/docs/languages
+        public static List<Lang> GetVisionSupportedLanguages()
+        {
+            var langs = new List<Lang>();
+            langs.Add(new Lang("Afrikaans", "af"));
+            langs.Add(new Lang("Albanian", "sq"));
+            langs.Add(new Lang("Arabic", "ar"));
+            langs.Add(new Lang("Armenian", "hy"));
+            langs.Add(new Lang("Belarusian", "be"));
+            langs.Add(new Lang("Bengali", "bn"));
+            langs.Add(new Lang("Bulgarian", "bg"));
+            langs.Add(new Lang("Catalan", "ca"));
+            langs.Add(new Lang("Chinese-Simplified", "zh"));
+            langs.Add(new Lang("Chinese-Traditional", "zh-Hant"));
+            langs.Add(new Lang("Croatian", "hr"));
+            langs.Add(new Lang("Czech", "cs"));
+            langs.Add(new Lang("Danish", "da"));
+            langs.Add(new Lang("Dutch", "nl"));
+            langs.Add(new Lang("English", "en"));
+            langs.Add(new Lang("Estonian", "et"));
+            langs.Add(new Lang("Filipino", "tl"));
+            langs.Add(new Lang("Finnish", "fi"));
+            langs.Add(new Lang("French", "fr"));
+            langs.Add(new Lang("German", "de"));
+            langs.Add(new Lang("Greek", "el"));
+            langs.Add(new Lang("Gujarati", "gu"));
+            langs.Add(new Lang("Hebrew", "iw"));
+            langs.Add(new Lang("Hindi", "hi"));
+            langs.Add(new Lang("Hungarian", "hu"));
+            langs.Add(new Lang("Icelandic", "is"));
+            langs.Add(new Lang("Indonesian", "id"));
+            langs.Add(new Lang("Italian", "it"));
+            langs.Add(new Lang("Japanese", "ja"));
+            langs.Add(new Lang("Kannada", "kn"));
+            langs.Add(new Lang("Khmer", "km"));
+            langs.Add(new Lang("Korean", "ko"));
+            langs.Add(new Lang("Lao", "lo"));
+            langs.Add(new Lang("Latvian", "lv"));
+            langs.Add(new Lang("Lithuanian", "lt"));
+            langs.Add(new Lang("Macedonian", "mk"));
+            langs.Add(new Lang("Malay", "ms"));
+            langs.Add(new Lang("Malayalam", "ml"));
+            langs.Add(new Lang("Marathi", "mr"));
+            langs.Add(new Lang("Nepali", "ne"));
+            langs.Add(new Lang("Norwegian", "no"));
+            langs.Add(new Lang("Persian", "fa"));
+            langs.Add(new Lang("Polish", "pl"));
+            langs.Add(new Lang("Portuguese", "pt"));
+            langs.Add(new Lang("Punjabi", "pa"));
+            langs.Add(new Lang("Romanian", "ro"));
+            langs.Add(new Lang("Russian", "ru"));
+            langs.Add(new Lang("Serbian", "sr"));
+            langs.Add(new Lang("Slovak", "sk"));
+            langs.Add(new Lang("Slovenian", "sl"));
+            langs.Add(new Lang("Spanish", "es"));
+            langs.Add(new Lang("Swedish", "sv"));
+            langs.Add(new Lang("Tamil", "ta"));
+            langs.Add(new Lang("Telugu", "te"));
+            langs.Add(new Lang("Thai", "th"));
+            langs.Add(new Lang("Turkish", "tr"));
+            langs.Add(new Lang("Ukrainian", "uk"));
+            langs.Add(new Lang("Vietnamese", "vi"));
+            langs.Add(new Lang("Yiddish", "yi"));
+            return langs;
+        }
+
+        // source : https://cloud.google.com/translate/docs/languages
+        public static List<Lang> GetTranslateSupportedLanguages()
+        {
+            var langs = new List<Lang>();
+            langs.Add(new Lang("Afrikaans", "af"));
+            langs.Add(new Lang("Albanian", "sq"));
+            langs.Add(new Lang("Amharic", "am"));
+            langs.Add(new Lang("Arabic", "ar"));
+            langs.Add(new Lang("Armenian", "hy"));
+            langs.Add(new Lang("Azerbaijani", "az"));
+            langs.Add(new Lang("Basque", "eu"));
+            langs.Add(new Lang("Belarusian", "be"));
+            langs.Add(new Lang("Bengali", "bn"));
+            langs.Add(new Lang("Bosnian", "bs"));
+            langs.Add(new Lang("Bulgarian", "bg"));
+            langs.Add(new Lang("Catalan", "ca"));
+            //langs.Add(new Lang("Cebuano", "ceb"));  // 文件說有支援但其實不能用
+            langs.Add(new Lang("Chinese-Simplified", "zh-CN"));
+            langs.Add(new Lang("Chinese-Traditional", "zh-TW"));
+            langs.Add(new Lang("Corsican", "co"));
+            langs.Add(new Lang("Croatian", "hr"));
+            langs.Add(new Lang("Czech", "cs"));
+            langs.Add(new Lang("Danish", "da"));
+            langs.Add(new Lang("Dutch", "nl"));
+            langs.Add(new Lang("English", "en"));
+            langs.Add(new Lang("Esperanto", "eo"));
+            langs.Add(new Lang("Estonian", "et"));
+            langs.Add(new Lang("Finnish", "fi"));
+            langs.Add(new Lang("French", "fr"));
+            langs.Add(new Lang("Frisian", "fy"));
+            langs.Add(new Lang("Galician", "gl"));
+            langs.Add(new Lang("Georgian", "ka"));
+            langs.Add(new Lang("German", "de"));
+            langs.Add(new Lang("Greek", "el"));
+            langs.Add(new Lang("Guarani", "gn"));
+            langs.Add(new Lang("Gujarati", "gu"));
+            langs.Add(new Lang("Haitian Creole", "ht"));
+            langs.Add(new Lang("Hausa", "ha"));
+            //langs.Add(new Lang("Hawaiian", "haw"));   // 文件說有支援但其實不能用
+            langs.Add(new Lang("Hebrew", "he"));
+            langs.Add(new Lang("Hindi", "hi"));
+            //langs.Add(new Lang("Hmong", "hmn"));   // 文件說有支援但其實不能用
+            langs.Add(new Lang("Hungarian", "hu"));
+            langs.Add(new Lang("Icelandic", "is"));
+            langs.Add(new Lang("Igbo", "ig"));
+            langs.Add(new Lang("Indonesian", "id"));
+            langs.Add(new Lang("Irish", "ga"));
+            langs.Add(new Lang("Italian", "it"));
+            langs.Add(new Lang("Japanese", "ja"));
+            langs.Add(new Lang("Javanese", "jv"));
+            langs.Add(new Lang("Kannada", "kn"));
+            langs.Add(new Lang("Kazakh", "kk"));
+            langs.Add(new Lang("Khmer", "km"));
+            langs.Add(new Lang("Kinyarwanda", "rw"));
+            langs.Add(new Lang("Korean", "ko"));
+            langs.Add(new Lang("Kurdish", "ku"));
+            langs.Add(new Lang("Kyrgyz", "ky"));
+            langs.Add(new Lang("Lao", "lo"));
+            langs.Add(new Lang("Latin", "la"));
+            langs.Add(new Lang("Latvian", "lv"));
+            langs.Add(new Lang("Lithuanian", "lt"));
+            langs.Add(new Lang("Luxembourgish", "lb"));
+            langs.Add(new Lang("Macedonian", "mk"));
+            langs.Add(new Lang("Malagasy", "mg"));
+            langs.Add(new Lang("Malay", "ms"));
+            langs.Add(new Lang("Malayalam", "ml"));
+            langs.Add(new Lang("Maltese", "mt"));
+            langs.Add(new Lang("Maori", "mi"));
+            langs.Add(new Lang("Marathi", "mr"));
+            langs.Add(new Lang("Mongolian", "mn"));
+            langs.Add(new Lang("Myanmar (Burmese)", "my"));
+            langs.Add(new Lang("Nepali", "ne"));
+            langs.Add(new Lang("Norwegian", "no"));
+            langs.Add(new Lang("Nyanja (Chichewa)", "ny"));
+            langs.Add(new Lang("Odia (Oriya)", "or"));
+            langs.Add(new Lang("Pashto", "ps"));
+            langs.Add(new Lang("Persian", "fa"));
+            langs.Add(new Lang("Polish", "pl"));
+            langs.Add(new Lang("Portuguese", "pt"));
+            langs.Add(new Lang("Punjabi", "pa"));
+            langs.Add(new Lang("Romanian", "ro"));
+            langs.Add(new Lang("Russian", "ru"));
+            langs.Add(new Lang("Samoan", "sm"));
+            langs.Add(new Lang("Sanskrit", "sa"));
+            langs.Add(new Lang("Scots Gaelic", "gd"));
+            langs.Add(new Lang("Serbian", "sr"));
+            langs.Add(new Lang("Sesotho", "st"));
+            langs.Add(new Lang("Shona", "sn"));
+            langs.Add(new Lang("Sindhi", "sd"));
+            langs.Add(new Lang("Sinhala (Sinhalese)	", "si"));
+            langs.Add(new Lang("Slovak", "sk"));
+            langs.Add(new Lang("Slovenian", "sl"));
+            langs.Add(new Lang("Somali", "so"));
+            langs.Add(new Lang("Spanish", "es"));
+            langs.Add(new Lang("Sundanese", "su"));
+            langs.Add(new Lang("Swahili", "sw"));
+            langs.Add(new Lang("Swedish", "sv"));
+            langs.Add(new Lang("Tagalog (Filipino)", "tl"));
+            langs.Add(new Lang("Tajik", "tg"));
+            langs.Add(new Lang("Tamil", "ta"));
+            langs.Add(new Lang("Tatar", "tt"));
+            langs.Add(new Lang("Telugu", "te"));
+            langs.Add(new Lang("Thai", "th"));
+            langs.Add(new Lang("Turkish", "tr"));
+            langs.Add(new Lang("Turkmen", "tk"));
+            langs.Add(new Lang("Ukrainian", "uk"));
+            langs.Add(new Lang("Urdu", "ur"));
+            langs.Add(new Lang("Uyghur", "ug"));
+            langs.Add(new Lang("Uzbek", "uz"));
+            langs.Add(new Lang("Vietnamese", "vi"));
+            langs.Add(new Lang("Welsh", "cy"));
+            langs.Add(new Lang("Xhosa", "xh"));
+            langs.Add(new Lang("Yiddish", "yi"));
+            langs.Add(new Lang("Yoruba", "yo"));
+            langs.Add(new Lang("Zulu", "zu"));
+            return langs;
+        }
     }
 }

+ 1 - 0
KdanCommon.csproj

@@ -125,6 +125,7 @@
     <Compile Include="CMSCollection\Data\JsonSetting.cs" />
     <Compile Include="CMSCollection\Data\ViewerEventBarSettingResponse.cs" />
     <Compile Include="CMSCollection\Data\WindowsCardsResponse.cs" />
+    <Compile Include="GoogleCloud\Data\Lang.cs" />
     <Compile Include="GoogleCloud\Data\Vision\ImgesRequest.cs" />
     <Compile Include="GoogleCloud\Data\Vision\ImgesResponse.cs" />
     <Compile Include="GoogleCloud\GoogleCloud.cs" />