Skip to content

Commit 23ec751

Browse files
authored
I18N을 적용을 위한 인터페이스 통합 (#103)
* refactor: language 관련 인터페이스, 상수 수정 messageInterface를 LanguageInterface로 이동 변경 langugage.ts에 있는 상수와 타입을 각 레이어로 분리 * fix: 인터페이스 수정 반영
1 parent 54b954c commit 23ec751

File tree

12 files changed

+32
-37
lines changed

12 files changed

+32
-37
lines changed

lib/api/exception/requestError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { REQUEST_LOCATION } from "@Library/api/exception/constant/requestLocation";
22
import { INTERNAL_SERVER_ERROR } from "@Library/api/exception/constant/statusCode";
33
import ExceptionInterface from "@Library/api/exception/interface";
4+
import { LanguageInterface } from "@Library/language/interface";
45
import { NETWORK_ERROR_MESSAGE } from "@Library/messages/constants/error";
5-
import MessageInterface from "@Library/messages/interface";
66

77
export default class RequestError implements ExceptionInterface {
88
readonly statusCode: number;
99
readonly requestLocation: string;
10-
readonly message: MessageInterface;
10+
readonly message: LanguageInterface;
1111

1212
constructor() {
1313
this.statusCode = INTERNAL_SERVER_ERROR;

lib/api/exception/responseError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import ExceptionInterface from "@Library/api/exception/interface";
2+
import { LanguageInterface } from "@Library/language/interface";
23
import { NOT_EXIST_MESSAGE } from "@Library/messages/constants/error";
3-
import MessageInterface from "@Library/messages/interface";
44

55
export default class ResponseError implements ExceptionInterface {
66
readonly statusCode: number;
77
readonly requestLocation: string;
8-
readonly message: MessageInterface;
8+
readonly message: LanguageInterface;
99

1010
constructor(errorObject: ExceptionInterface) {
1111
this.statusCode = errorObject.statusCode;

lib/api/exception/unknownError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { UNKNOWN_LOCATION } from "@Library/api/exception/constant/requestLocation";
22
import { INTERNAL_SERVER_ERROR } from "@Library/api/exception/constant/statusCode";
33
import ExceptionInterface from "@Library/api/exception/interface";
4+
import { LanguageInterface } from "@Library/language/interface";
45
import { NETWORK_ERROR_MESSAGE } from "@Library/messages/constants/error";
5-
import MessageInterface from "@Library/messages/interface";
66

77
export default class UnknownError implements ExceptionInterface {
88
readonly statusCode: number;
99
readonly requestLocation: string;
10-
readonly message: MessageInterface;
10+
readonly message: LanguageInterface;
1111

1212
constructor() {
1313
this.statusCode = INTERNAL_SERVER_ERROR;

lib/date-fns/changeDateToDateFnsFormat.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { format, formatDistanceToNow } from "date-fns";
22

3+
import { DATE_FNS_LANGUAGE, JUST_NOW } from "@Library/date-fns/constants";
34
import { store } from "@Redux/store";
45

5-
import { JUST_NOW } from "@DateFns/constants";
6-
import { DATE_FNS_LANGUAGE } from "@Language/language";
7-
86
export default function changeDateToDateFnsFormat(date: string): string {
97
const { language } = store.getState().TILog_Info;
108

lib/date-fns/constants/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { LANGUAGE } from "@Language/language";
1+
import { enUS, ko } from "date-fns/locale";
22

3-
type DateInterface = Record<typeof LANGUAGE[keyof typeof LANGUAGE], string>;
3+
export const DATE_FNS_LANGUAGE = {
4+
ko,
5+
en: enUS,
6+
} as const;
47

5-
export const JUST_NOW: DateInterface = {
8+
export const JUST_NOW = {
69
ko: "방금 전",
710
en: "Just Now",
811
};

lib/language/constant/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const LANGUAGE = {
2+
ko: "ko",
3+
en: "en",
4+
} as const;
5+
export default LANGUAGE;

lib/language/getUserLanguage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { LanguageUnionType, LANGUAGE } from "@Language/language";
1+
import LANGUAGE from "@Library/language/constant";
2+
import { LanguageUnionType } from "@Library/language/interface";
23

34
export default function getUserLanguage(): LanguageUnionType {
45
const language = navigator.language.substring(0, 2).toLowerCase();
@@ -7,5 +8,5 @@ export default function getUserLanguage(): LanguageUnionType {
78
const userLanguage = language as LanguageUnionType;
89
return LANGUAGE[userLanguage];
910
}
10-
return LANGUAGE.ko;
11+
return LANGUAGE.en;
1112
}

lib/language/interface/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import LANGUAGE from "@Library/language/constant";
2+
3+
export type LanguageInterface = Record<
4+
typeof LANGUAGE[keyof typeof LANGUAGE],
5+
string
6+
>;
7+
export type LanguageUnionType = keyof typeof LANGUAGE;

lib/language/language.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/messages/constants/error/networkErrorMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import MessageInterface from "lib/messages/interface";
1+
import { LanguageInterface } from "@Library/language/interface";
22

3-
const NETWORK_ERROR_MESSAGE: MessageInterface = {
3+
const NETWORK_ERROR_MESSAGE: LanguageInterface = {
44
ko: "서버와 연결이 끊겼습니다.",
55
en: "NetWork Error.",
66
};

0 commit comments

Comments
 (0)