Merge pull request #125 from charliewang95/users/charlwan/locale

Update locale export
This commit is contained in:
Charlie Wang 2022-04-12 20:34:47 -07:00 коммит произвёл GitHub
Родитель 91ec7fb10b 97641b2a10
Коммит 077d17c22a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -4,16 +4,16 @@ const locale = require('../../src/utils/locale');
describe('Locales', () => { describe('Locales', () => {
it('locale.getLocaleStringFromId() should return correctly', () => { it('locale.getLocaleStringFromId() should return correctly', () => {
expect(locale.getLocaleStringFromId("1033")).toBe("en-us"); expect(locale.getLocaleStringFromId("1033")).toBe("en-us");
expect(locale.getLocaleStringFromId(1033)).toBe(""); expect(locale.getLocaleStringFromId(1033)).toBe("en-us");
expect(locale.getLocaleStringFromId("1133")).toBe(""); expect(locale.getLocaleStringFromId("1133")).toBe("en-us");
expect(locale.getLocaleStringFromId("1058")).toBe("uk-ua"); expect(locale.getLocaleStringFromId("1058")).toBe("uk-ua");
expect(locale.getLocaleStringFromId("")).toBe(""); expect(locale.getLocaleStringFromId("")).toBe("en-us");
}); });
it('locale.getLocaleIdFromString() should return correctly', () => { it('locale.getLocaleIdFromString() should return correctly', () => {
expect(locale.getLocaleIdFromString("en-us")).toBe("1033"); expect(locale.getLocaleIdFromString("en-us")).toBe("1033");
expect(locale.getLocaleIdFromString("en-uus")).toBe(""); expect(locale.getLocaleIdFromString("en-uus")).toBe("1033");
expect(locale.getLocaleIdFromString("")).toBe(""); expect(locale.getLocaleIdFromString("")).toBe("1033");
expect(locale.getLocaleIdFromString("zh-cn")).toBe("2052"); expect(locale.getLocaleIdFromString("zh-cn")).toBe("2052");
}); });
}); });

Просмотреть файл

@ -1,14 +1,16 @@
import {SDKProvider as OCSDKProvider, uuidv4 } from "@microsoft/ocsdk"; import {SDKProvider as OCSDKProvider, uuidv4} from "@microsoft/ocsdk";
import {SDKProvider as IC3SDKProvider} from '@microsoft/omnichannel-ic3core'; import { defaultLocaleId, defaultLocaleString, getLocaleIdFromString, getLocaleStringFromId } from "./utils/locale";
import OmnichannelChatSDK from "./OmnichannelChatSDK"; import { isCustomerMessage, isSystemMessage } from "./utils/utilities";
import ChatSDKMessage from "./core/messaging/ChatSDKMessage"; import ChatSDKMessage from "./core/messaging/ChatSDKMessage";
import DeliveryMode from "@microsoft/omnichannel-ic3core/lib/model/DeliveryMode";
import {SDKProvider as IC3SDKProvider} from '@microsoft/omnichannel-ic3core';
import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo";
import IRawMessage from "@microsoft/omnichannel-ic3core/lib/model/IRawMessage"; import IRawMessage from "@microsoft/omnichannel-ic3core/lib/model/IRawMessage";
import MessageContentType from "@microsoft/omnichannel-ic3core/lib/model/MessageContentType"; import MessageContentType from "@microsoft/omnichannel-ic3core/lib/model/MessageContentType";
import DeliveryMode from "@microsoft/omnichannel-ic3core/lib/model/DeliveryMode";
import MessageType from "@microsoft/omnichannel-ic3core/lib/model/MessageType"; import MessageType from "@microsoft/omnichannel-ic3core/lib/model/MessageType";
import OmnichannelChatSDK from "./OmnichannelChatSDK";
import PersonType from "@microsoft/omnichannel-ic3core/lib/model/PersonType"; import PersonType from "@microsoft/omnichannel-ic3core/lib/model/PersonType";
import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo";
import { isSystemMessage, isCustomerMessage } from "./utils/utilities";
export { export {
OmnichannelChatSDK, OmnichannelChatSDK,
@ -23,7 +25,11 @@ export {
PersonType, PersonType,
IFileInfo, IFileInfo,
isSystemMessage, isSystemMessage,
isCustomerMessage isCustomerMessage,
getLocaleStringFromId,
getLocaleIdFromString,
defaultLocaleId,
defaultLocaleString
} }
export default { export default {

Просмотреть файл

@ -49,13 +49,14 @@ const localeList: any = { // eslint-disable-line @typescript-eslint/no-explicit-
export const getLocaleStringFromId = (id: string): string => { export const getLocaleStringFromId = (id: string): string => {
const localeId = Object.keys(localeList).find(key => key === id); const localeId = Object.keys(localeList).find(key => key === id);
return localeId ? localeList[localeId] : ""; return localeId ? localeList[localeId] : defaultLocaleString;
} }
export const getLocaleIdFromString = (value: string): string => { export const getLocaleIdFromString = (value: string): string => {
const localeId = Object.keys(localeList).find(key => localeList[key] === value); const localeId = Object.keys(localeList).find(key => localeList[key] === value);
return localeId ?? ""; return localeId ?? defaultLocaleId;
} }
export const defaultLocaleId = getLocaleIdFromString("en-us"); export const defaultLocaleId = "1033";
export const defaultLocaleString = "en-us";