Codebase list fcitx-cloudpinyin / 3ef0706
New upstream version 0.3.7 Boyuan Yang 4 years ago
6 changed file(s) with 54 addition(s) and 251 deletion(s). Raw diff Collapse all Expand all
22 # This file is distributed under the same license as the PACKAGE package.
33 #
44 # Translators:
5 # Robert Antoni Buj Gelonch <rbuj@fedoraproject.org>, 2017-2018
56 # Walter Garcia-Fontes <walter.garcia@upf.edu>, 2016
67 msgid ""
78 msgstr ""
89 "Project-Id-Version: fcitx\n"
910 "Report-Msgid-Bugs-To: fcitx-dev@googlegroups.com\n"
10 "POT-Creation-Date: 2017-09-14 16:02-0700\n"
11 "PO-Revision-Date: 2017-08-03 16:57+0000\n"
12 "Last-Translator: Walter Garcia-Fontes <walter.garcia@upf.edu>\n"
11 "POT-Creation-Date: 2019-11-03 12:27-0800\n"
12 "PO-Revision-Date: 2018-06-13 07:07+0000\n"
13 "Last-Translator: Robert Antoni Buj Gelonch <rbuj@fedoraproject.org>\n"
1314 "Language-Team: Catalan (http://www.transifex.com/fcitx/fcitx/language/ca/)\n"
1415 "Language: ca\n"
1516 "MIME-Version: 1.0\n"
1718 "Content-Transfer-Encoding: 8bit\n"
1819 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
1920
20 #: src/cloudpinyin.c:684
21 #: src/cloudpinyin.c:685
2122 msgid " (via cloud)"
2223 msgstr "(via el núvol)"
2324
2425 #: src/fcitx-cloudpinyin.conf.in:4
2526 msgid "Add Cloud Pinyin Support to Pinyin Input Method"
26 msgstr "Afegeix suport de pinyin de núvol al mètode d'entrada pinying"
27 msgstr ""
28 "Afegeix la compatibilitat amb pinyin al núvol al mètode d'entrada pinying"
2729
2830 #: src/fcitx-cloudpinyin.desc:24
2931 msgid "Baidu"
3032 msgstr "Baidu"
3133
32 #: src/cloudpinyin.c:619 src/fcitx-cloudpinyin.conf.in:3
34 #: src/cloudpinyin.c:620 src/fcitx-cloudpinyin.conf.in:3
3335 msgid "Cloud Pinyin"
34 msgstr "Pinyin de núvol"
36 msgstr "Pinyin al núvol"
3537
3638 #: src/fcitx-cloudpinyin.desc:5
3739 msgid "Cloud Pinyin Candidate Word Order"
38 msgstr "Ordre de paraules candidates del pinyin de núvol"
40 msgstr "Ordre de les paraules candidates del pinyin al núvol"
3941
4042 #: src/fcitx-cloudpinyin.desc:21
4143 msgid "Cloud Pinyin Source"
42 msgstr "Font de pinyin de núvol"
44 msgstr "Origen de pinyin al núvol"
45
46 #: src/cloudpinyin.c:622
47 msgid "Cloud Pinyin is Disabled."
48 msgstr "El pinyin al núvol està inhabilitat"
4349
4450 #: src/cloudpinyin.c:621
45 msgid "Cloud Pinyin is Disabled."
46 msgstr "El pinyin de núvol està desactivat"
47
48 #: src/cloudpinyin.c:620
4951 msgid "Cloud Pinyin is Enabled."
50 msgstr "El pinyin de núvol està activat."
52 msgstr "El pinyin al núvol està habilitat."
5153
5254 #: src/fcitx-cloudpinyin.desc:1 src/fcitx-cloudpinyin.desc:7
5355 #: src/fcitx-cloudpinyin.desc:13 src/fcitx-cloudpinyin.desc:18
5456 #: src/fcitx-cloudpinyin.desc:26 src/fcitx-cloudpinyin.desc:32
5557 msgid "CloudPinyin"
56 msgstr "PinyinNúvol"
58 msgstr "Pinyin al núvol"
5759
5860 #: src/fcitx-cloudpinyin.desc:30
5961 msgid "Disable Cloud Pinyin When you are using mobile can save your network"
6062 msgstr ""
61 "Desactivar el pinyin de núvol quan esteu usant dades mòbil pot estalviar la "
63 "Inhabilitar pinyin al núvol quan esteu utilitzant el mòbil pot estalviar la "
6264 "vostra xarxa"
6365
6466 #: src/fcitx-cloudpinyin.desc:16
6567 msgid "Don't Show the 'via cloud' hint"
66 msgstr "No mostris la pista «via núvol»"
68 msgstr "No mostris els suggerents «via núvol»"
6769
6870 #: src/fcitx-cloudpinyin.desc:35
6971 msgid "Enabled"
70 msgstr "Activat"
72 msgstr "Habilitat"
7173
7274 #: src/fcitx-cloudpinyin.desc:23
7375 msgid "Google"
7577
7678 #: src/fcitx-cloudpinyin.desc:11
7779 msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
78 msgstr "Longitud mínima de pinyin per activar pinyin de núvol"
80 msgstr "Longitud mínima de pinyin per activar pinyin al núvol"
7981
8082 #: src/fcitx-cloudpinyin.desc:29
8183 msgid "Toggle Cloud Pinyin enabled status"
82 msgstr "Commuta l'estat d'activació del pinyin de núvol"
84 msgstr "Commuta l'estat d'activació del pinyin al núvol"
22 # This file is distributed under the same license as the PACKAGE package.
33 #
44 # Translators:
5 # TotalCaesar659 <x24cm5b8c54q6szxw@yandex.ru>, 2016
5 # TotalCaesar659 <x24cm5b8c54q6szxw@yandex.ru>, 2016-2017
66 msgid ""
77 msgstr ""
88 "Project-Id-Version: fcitx\n"
99 "Report-Msgid-Bugs-To: fcitx-dev@googlegroups.com\n"
10 "POT-Creation-Date: 2017-09-14 16:02-0700\n"
11 "PO-Revision-Date: 2017-08-03 16:57+0000\n"
10 "POT-Creation-Date: 2017-11-28 00:03-0800\n"
11 "PO-Revision-Date: 2017-11-27 15:15+0000\n"
1212 "Last-Translator: TotalCaesar659 <x24cm5b8c54q6szxw@yandex.ru>\n"
1313 "Language-Team: Russian (http://www.transifex.com/fcitx/fcitx/language/ru/)\n"
1414 "Language: ru\n"
1919 "%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
2020 "%100>=11 && n%100<=14)? 2 : 3);\n"
2121
22 #: src/cloudpinyin.c:684
22 #: src/cloudpinyin.c:685
2323 msgid " (via cloud)"
2424 msgstr "(через облако)"
2525
2626 #: src/fcitx-cloudpinyin.conf.in:4
2727 msgid "Add Cloud Pinyin Support to Pinyin Input Method"
28 msgstr "Добавить поддержку облака пиньинь для метода ввода пиньинь"
28 msgstr "Добавить поддержку Cloud Pinyin для метода ввода пиньинь"
2929
3030 #: src/fcitx-cloudpinyin.desc:24
3131 msgid "Baidu"
3232 msgstr "Baidu"
3333
34 #: src/cloudpinyin.c:619 src/fcitx-cloudpinyin.conf.in:3
34 #: src/cloudpinyin.c:620 src/fcitx-cloudpinyin.conf.in:3
3535 msgid "Cloud Pinyin"
36 msgstr "Облако пиньинь"
36 msgstr "Cloud Pinyin"
3737
3838 #: src/fcitx-cloudpinyin.desc:5
3939 msgid "Cloud Pinyin Candidate Word Order"
40 msgstr "Порядок слов-кандидатов облака пиньинь"
40 msgstr "Порядок слов-кандидатов Cloud Pinyin"
4141
4242 #: src/fcitx-cloudpinyin.desc:21
4343 msgid "Cloud Pinyin Source"
4444 msgstr "Источник облака пиньинь"
4545
46 #: src/cloudpinyin.c:622
47 msgid "Cloud Pinyin is Disabled."
48 msgstr "Cloud Pinyin отключен."
49
4650 #: src/cloudpinyin.c:621
47 msgid "Cloud Pinyin is Disabled."
48 msgstr "Облако пиньинь отключено."
49
50 #: src/cloudpinyin.c:620
5151 msgid "Cloud Pinyin is Enabled."
52 msgstr "Облако пиньинь включено."
52 msgstr "Cloud Pinyin включен."
5353
5454 #: src/fcitx-cloudpinyin.desc:1 src/fcitx-cloudpinyin.desc:7
5555 #: src/fcitx-cloudpinyin.desc:13 src/fcitx-cloudpinyin.desc:18
689689 }
690690
691691 #define LOADING_TIME_QUICK_THRESHOLD 300
692 #define DUP_PLACE_HOLDER "\xe2\x98\xba"
692 #define DUP_PLACE_HOLDER "\xe2\x98\x81"
693693
694694 void CloudPinyinFillCandidateWord(FcitxCloudPinyin* cloudpinyin,
695695 const char* pinyin)
77 #include <ctype.h>
88 #include "cloudpinyin.h"
99
10 static inline boolean ishex(char ch)
11 {
12 if ((ch >= '0' && ch <= '9') || (ch >='a' && ch <='f') || (ch >='A' && ch <='F'))
13 return true;
14 return false;
15 }
16
17 static inline unsigned char tohex(char ch)
18 {
19 if (ch >= '0' && ch <= '9')
20 return ch - '0';
21 if (ch >='a' && ch <='f')
22 return ch - 'a' + 10;
23 if (ch >='A' && ch <='F')
24 return ch - 'A' + 10;
25 return 0;
26 }
27
28 void SogouParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
29 {
30 char* str = fcitx_utils_trim(queue->str);
31 const char* ime_patch_key = "ime_patch_key = \"";
32 size_t len = strlen(str);
33 if (len == SOGOU_KEY_LENGTH + strlen(ime_patch_key) + 1
34 && strncmp(str, ime_patch_key, strlen(ime_patch_key)) == 0
35 && str[len - 1] == '\"') {
36 sscanf(str,"ime_patch_key = \"%s\"", cloudpinyin->key);
37 cloudpinyin->initialized = true;
38 cloudpinyin->key[SOGOU_KEY_LENGTH] = '\0';
39 }
40
41 free(str);
42 }
43
44 char* MapSogouStringToHalf(const char* string)
45 {
46 const char* s = string;
47 const char* sn;
48 size_t len = strlen(string);
49 char* half = fcitx_utils_malloc0(sizeof(char) * (len + 1));
50 char* halfp = half;
51 int upperCount = 0;
52
53 while (*s) {
54 unsigned int chr = 0;
55
56 sn = fcitx_utf8_get_char(s, &chr);
57
58 /* from A to Z */
59 if ((chr >= 0xff21 && chr <= 0xff3a) || (chr >= 0xff41 && chr <= 0xff5a)) {
60 *halfp = (char) (chr & 0xff) + 0x20;
61 if (isupper(*halfp))
62 upperCount ++;
63 halfp ++;
64 }
65 else {
66 while(s < sn) {
67 *halfp = *s;
68 if (isupper(*halfp))
69 upperCount ++;
70 s++;
71 halfp++;
72 }
73 }
74
75 s = sn;
76 }
77 if (*half && isupper(*half) && upperCount == 1) {
78 *half = tolower(*half);
79 }
80 return half;
81 }
82
83 char* SogouParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
84 {
85 char *start = NULL, *end = NULL;
86 if ((start = strchr(queue->str, '"')) != NULL && (end = strstr(queue->str, "%EF%BC%9A")) != NULL)
87 {
88 start ++;
89 if (start < end)
90 {
91 size_t length = end - start;
92 int conv_length;
93 char *unescapedstring = curl_easy_unescape(queue->curl, start, length, &conv_length);
94 char *realstring = MapSogouStringToHalf(unescapedstring);
95 curl_free(unescapedstring);
96 return realstring;
97 }
98 }
99 return NULL;
100 }
101
102 void QQParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
103 {
104 char* str = fcitx_utils_trim(queue->str);
105 const char* ime_patch_key = "{\"key\":\"";
106 if (strncmp(str, ime_patch_key, strlen(ime_patch_key)) == 0)
107 {
108 if (sscanf(str,"{\"key\":\"%32s\",\"ret\":\"suc\"}", cloudpinyin->key) > 0)
109 {
110 cloudpinyin->initialized = true;
111 cloudpinyin->key[QQ_KEY_LENGTH] = '\0';
112 }
113 }
114
115 free(str);
116 }
117
118 char* QQParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
119 {
120 char *start = NULL, *end = NULL;
121 if ((start = strstr(queue->str, "\"rs\":[\"")) != NULL)
122 {
123 start += strlen( "\"rs\":[\"");
124 if ((end = strstr(start, "\"")) != NULL)
125 {
126 size_t length = end - start;
127 char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
128 strncpy(realstring, start, length);
129 realstring[length] = '\0';
130 return realstring;
131 }
132 }
133 return NULL;
134 }
135
13610 char* GoogleParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
13711 {
13812 char *start = NULL, *end = NULL;
13 if (!queue->str) {
14 return NULL;
15 }
13916 if ((start = strstr(queue->str, "\",[\"")) != NULL)
14017 {
14118 start += strlen( "\",[\"");
14522 char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
14623 strncpy(realstring, start, length);
14724 realstring[length] = '\0';
148 return realstring;
25 if (fcitx_utf8_check_string(realstring)) {
26 return realstring;
27 } else {
28 free(realstring);
29 return NULL;
30 }
14931 }
15032 }
15133 return NULL;
15436 char* BaiduParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
15537 {
15638 char *start = NULL, *end = NULL;
157 static iconv_t conv = 0;
158 if (conv == 0)
159 conv = iconv_open("utf-8", "utf-16be");
160
161 if (conv == (iconv_t)(-1))
39 if (!queue->str) {
16240 return NULL;
163 if ((start = strstr(queue->str, "[[[\"")) != NULL)
41 }
42 if ((start = strstr(queue->str, "[[\"")) != NULL)
16443 {
165 start += strlen( "[[[\"");
44 start += strlen( "[[\"");
16645 if ((end = strstr(start, "\",")) != NULL)
16746 {
16847 size_t length = end - start;
169 if (length % 6 != 0 || length == 0)
170 return NULL;
171
172 size_t i = 0, j = 0;
173 char* buf = fcitx_utils_malloc0((length / 6 + 1) * 2);
174 while (i < length)
175 {
176 if (start[i] == '\\' && start[i+1] == 'u')
177 {
178 if (ishex(start[i+2]) && ishex(start[i+3]) && ishex(start[i+4]) && ishex(start[i+5]))
179 {
180 buf[j++] = (tohex(start[i+2]) << 4) | tohex(start[i+3]);
181 buf[j++] = (tohex(start[i+4]) << 4) | tohex(start[i+5]);
182 }
183 else
184 break;
185 }
186
187 i += 6;
188 }
189
190 if (i != length)
191 {
192 free(buf);
193 return NULL;
194 }
195 buf[j++] = 0;
196 buf[j++] = 0;
197 size_t len = UTF8_MAX_LENGTH * (length / 6) * sizeof(char);
198 char* realstring = fcitx_utils_malloc0(UTF8_MAX_LENGTH * (length / 6) * sizeof(char));
199 IconvStr p = buf; char *pp = realstring;
200 iconv(conv, &p, &j, &pp, &len);
201
202 free(buf);
203 if (fcitx_utf8_check_string(realstring))
48 char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
49 strncpy(realstring, start, length);
50 realstring[length] = '\0';
51 if (fcitx_utf8_check_string(realstring)) {
20452 return realstring;
205 else
206 {
53 } else {
20754 free(realstring);
20855 return NULL;
20956 }
0 include_directories(
1 ${PROJECT_SOURCE_DIR}/src
2 ${PROJECT_BINARY_DIR}
3 ${CMAKE_CURRENT_SOURCE_DIR}
4 ${CURL_INCLUDE_DIRS}
5 ${FCITX4_FCITX_INCLUDE_DIRS}
6 ${FCITX4_FCITX_CONFIG_INCLUDE_DIRS}
7 ${FCITX4_FCITX_UTILS_INCLUDE_DIRS}
8 ${LIBINTL_INCLUDE_DIR}
9 ${PTHREAD_INCLUDE_DIR}
10 )
11
12 link_directories(
13 ${CURL_LIBRARY_DIRS}
14 ${FCITX4_FCITX_UTILS_LIBRARY_DIRS}
15 )
16
17 add_executable(testhalf testhalf.c ../src/parse.c)
18
19 target_link_libraries( testhalf
20 ${PTHREAD_LIBRARIES}
21 ${FCITX4_FCITX_UTILS_LIBRARIES}
22 ${CURL_LIBRARIES}
23 ${LIBINTL_LIBRARIES}
24 )
25
26 add_test(testhalf testhalf)
+0
-19
test/testhalf.c less more
0 #include "parse.h"
1
2 #include <assert.h>
3
4 int main(int argc, char* argv[])
5 {
6 char* result = MapSogouStringToHalf("ABCD");
7 printf("%s\n", result);
8 assert(strcmp(result, "ABCD") == 0);
9
10 free(result);
11
12 result = MapSogouStringToHalf("我a测b你CD的");
13 printf("%s\n", result);
14 assert(strcmp(result, "我a测b你CD的") == 0);
15
16 free(result);
17 return 0;
18 }