Skip to content

Commit b4dbf13

Browse files
committed
feat: capitalize translation result
1 parent c29ed44 commit b4dbf13

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

client/src/lib/translate/baidu.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { URLSearchParams } from 'url';
22
import { v4 as uuidv4 } from 'uuid';
33
import md5 from 'blueimp-md5';
44
import axios from 'axios';
5+
import { capitalize } from './util';
56

67
export interface BaiduResponse
78
{
@@ -58,7 +59,7 @@ export const getBaiduSource = (query: string, isChinese?: boolean): string =>
5859
* @param {string} query - 将要翻译的中文文本
5960
* @return {*} {Promise<string[]>} - 翻译结果数组
6061
*/
61-
export const getZhTranslation = async (query: string): Promise<string[]> =>
62+
export const getBaiduZhTranslation = async (query: string): Promise<string[]> =>
6263
{
6364
if (!query) return []
6465

@@ -75,5 +76,5 @@ export const getZhTranslation = async (query: string): Promise<string[]> =>
7576

7677
console.log('translationResult', result)
7778

78-
return trans_result.map(r => r.dst)
79+
return trans_result.map(r => capitalize(r.dst))
7980
}

client/src/lib/translate/util.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
/**
3+
* 讲英文字符串第一个字符转为大写
4+
*
5+
* @param {string} string
6+
* @return {*}
7+
*/
8+
export const capitalize = (string: string) =>
9+
{
10+
return string.charAt(0).toUpperCase() + string.slice(1);
11+
}

0 commit comments

Comments
 (0)