detect lang remote
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { CACHE_NAME } from "../config";
|
||||
import { browser } from "./browser";
|
||||
import { apiBaiduLangdetect } from "../apis";
|
||||
|
||||
/**
|
||||
* 清除缓存数据
|
||||
@@ -13,15 +14,24 @@ export const tryClearCaches = async () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 本地语言识别
|
||||
* 语言识别
|
||||
* @param {*} q
|
||||
* @returns
|
||||
*/
|
||||
export const tryDetectLang = async (q) => {
|
||||
export const tryDetectLang = async (q, useRemote = false) => {
|
||||
let lang = "";
|
||||
|
||||
try {
|
||||
const res = await browser?.i18n?.detectLanguage(q);
|
||||
return res?.languages?.[0]?.language;
|
||||
if (useRemote) {
|
||||
lang = await apiBaiduLangdetect(q);
|
||||
}
|
||||
if (!lang) {
|
||||
const res = await browser?.i18n?.detectLanguage(q);
|
||||
lang = res?.languages?.[0]?.language;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("[detect lang]", err.message);
|
||||
}
|
||||
|
||||
return lang;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user