fix. 개발 도구 적용. (typescript, prettier, es-lint)
This commit is contained in:
@@ -6,15 +6,20 @@ import { DEFAULT_COVERAGES } from '@/i18n.config'
|
||||
*/
|
||||
export const useDynamicI18nRoutes = () => {
|
||||
const gameDataStore = useGameDataStore()
|
||||
|
||||
|
||||
/**
|
||||
* 현재 gameData의 lang_codes를 기반으로 허용된 언어 목록을 반환
|
||||
*/
|
||||
const getAllowedLangCodes = (): string[] => {
|
||||
const gameData = gameDataStore.gameData
|
||||
return gameData?.lang_codes || []
|
||||
// Ensure we only return string values and filter out undefined/null
|
||||
return Array.isArray(gameData?.lang_codes)
|
||||
? gameData.lang_codes.filter(
|
||||
(code): code is string => typeof code === 'string'
|
||||
)
|
||||
: []
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 특정 언어가 허용되는지 확인
|
||||
*/
|
||||
@@ -22,7 +27,7 @@ export const useDynamicI18nRoutes = () => {
|
||||
const allowedLangCodes = getAllowedLangCodes()
|
||||
return allowedLangCodes.length === 0 || allowedLangCodes.includes(langCode)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* defineI18nRoute에서 사용할 수 있는 언어 제외 설정을 생성
|
||||
* @param pagePath - 페이지 경로 (선택사항)
|
||||
@@ -30,18 +35,18 @@ export const useDynamicI18nRoutes = () => {
|
||||
*/
|
||||
const getI18nRouteConfig = (pagePath?: string) => {
|
||||
const allowedLangCodes = getAllowedLangCodes()
|
||||
|
||||
|
||||
// 허용된 언어가 없으면 모든 언어 허용
|
||||
if (allowedLangCodes.length === 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
||||
// 허용된 언어만 포함하는 설정 반환
|
||||
return {
|
||||
locales: allowedLangCodes
|
||||
locales: allowedLangCodes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 특정 언어를 제외하는 설정을 생성
|
||||
* @param excludedLangCodes - 제외할 언어 코드 배열
|
||||
@@ -49,21 +54,33 @@ export const useDynamicI18nRoutes = () => {
|
||||
*/
|
||||
const getExcludedLangConfig = (excludedLangCodes: string[]) => {
|
||||
const allowedLangCodes = getAllowedLangCodes()
|
||||
|
||||
|
||||
// 허용된 언어에서 제외할 언어를 제거
|
||||
const finalAllowedCodes = allowedLangCodes.length > 0
|
||||
? allowedLangCodes.filter(code => !excludedLangCodes.includes(code))
|
||||
: ['en', 'ja', 'ko', 'zh-tw', 'fr', 'de', 'es', 'pt', 'th', 'zh-cn'].filter(code => !excludedLangCodes.includes(code))
|
||||
|
||||
const finalAllowedCodes =
|
||||
allowedLangCodes.length > 0
|
||||
? allowedLangCodes.filter(code => !excludedLangCodes.includes(code))
|
||||
: [
|
||||
'en',
|
||||
'ja',
|
||||
'ko',
|
||||
'zh-tw',
|
||||
'fr',
|
||||
'de',
|
||||
'es',
|
||||
'pt',
|
||||
'th',
|
||||
'zh-cn',
|
||||
].filter(code => !excludedLangCodes.includes(code))
|
||||
|
||||
return {
|
||||
locales: finalAllowedCodes
|
||||
locales: finalAllowedCodes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
getAllowedLangCodes,
|
||||
isLangAllowed,
|
||||
getI18nRouteConfig,
|
||||
getExcludedLangConfig
|
||||
getExcludedLangConfig,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
import { getHeader } from "h3";
|
||||
import { useRuntimeConfig, useRequestEvent } from "nuxt/app";
|
||||
import { getHeader } from 'h3'
|
||||
import { useRuntimeConfig, useRequestEvent } from 'nuxt/app'
|
||||
|
||||
export const useGetGameAlias = () => {
|
||||
const config = useRuntimeConfig();
|
||||
const baseDomain = (config.public.baseDomain || ".onstove.com") as string;
|
||||
const config = useRuntimeConfig()
|
||||
const baseDomain = (config.public.baseDomain || '.onstove.com') as string
|
||||
|
||||
// 서버 사이드에서 실행되는 경우
|
||||
if (!import.meta.client) {
|
||||
try {
|
||||
const event = useRequestEvent();
|
||||
const event = useRequestEvent()
|
||||
|
||||
if (event) {
|
||||
// 미들웨어에서 설정한 gameAlias가 있다면 우선 사용
|
||||
if (event.context.gameAlias) {
|
||||
return event.context.gameAlias;
|
||||
return event.context.gameAlias
|
||||
}
|
||||
|
||||
const host = getHeader(event, "host") || "";
|
||||
const isGameAliasExtractable = host.includes(baseDomain);
|
||||
const host = getHeader(event, 'host') || ''
|
||||
const isGameAliasExtractable = host.includes(baseDomain)
|
||||
|
||||
if (isGameAliasExtractable) {
|
||||
const subdomain = host.split(".")[0];
|
||||
const subdomain = host.split('.')[0]
|
||||
|
||||
if (subdomain && subdomain !== "www") {
|
||||
return subdomain;
|
||||
if (subdomain && subdomain !== 'www') {
|
||||
return subdomain
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("useGetGameAlias server error: ", error);
|
||||
console.error('useGetGameAlias server error: ', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 클라이언트 사이드에서 실행되는 경우
|
||||
if (import.meta.client) {
|
||||
try {
|
||||
const host = window.location.host;
|
||||
const isGameAliasExtractable = host.includes(baseDomain);
|
||||
const host = window.location.host
|
||||
const isGameAliasExtractable = host.includes(baseDomain)
|
||||
|
||||
if (isGameAliasExtractable) {
|
||||
const subdomain = host.split(".")[0];
|
||||
const subdomain = host.split('.')[0]
|
||||
|
||||
if (subdomain && subdomain !== "www") {
|
||||
return subdomain;
|
||||
if (subdomain && subdomain !== 'www') {
|
||||
return subdomain
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("useGetGameAlias client error: ", error);
|
||||
console.error('useGetGameAlias client error: ', error)
|
||||
}
|
||||
}
|
||||
return "";
|
||||
};
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -2,38 +2,38 @@ export const usePathResolver = () => {
|
||||
const getPathAfterLanguage = (url?: string): string => {
|
||||
// URL이 제공되지 않으면 현재 URL 사용
|
||||
const targetUrl =
|
||||
url || (import.meta.client ? window.location.pathname : "");
|
||||
url || (import.meta.client ? window.location.pathname : '')
|
||||
|
||||
// URL에서 언어 코드 패턴을 찾아서 그 뒤의 경로를 추출
|
||||
// 예: /ko/about/story -> /about/story
|
||||
// 예: /en/test/page -> /test/page
|
||||
// 예: /ko -> "" (빈 문자열)
|
||||
const languagePattern = /^\/[a-z]{2}\/(.+)$/;
|
||||
const match = targetUrl.match(languagePattern);
|
||||
const languagePattern = /^\/[a-z]{2}\/(.+)$/
|
||||
const match = targetUrl.match(languagePattern)
|
||||
|
||||
if (match && match[1]) {
|
||||
return `/${match[1]}`;
|
||||
return `/${match[1]}`
|
||||
}
|
||||
|
||||
// 언어 코드만 있고 뒤에 아무것도 없는 경우 (예: /ko, /en)
|
||||
const languageOnlyPattern = /^\/[a-z]{2}$/;
|
||||
const languageOnlyPattern = /^\/[a-z]{2}$/
|
||||
if (languageOnlyPattern.test(targetUrl)) {
|
||||
return "";
|
||||
return ''
|
||||
}
|
||||
|
||||
// 언어 코드가 없는 경우 원본 경로 그대로 반환 (이미 /로 시작)
|
||||
return targetUrl;
|
||||
};
|
||||
return targetUrl
|
||||
}
|
||||
|
||||
const getCurrentPath = (): string => {
|
||||
if (import.meta.client) {
|
||||
return getPathAfterLanguage();
|
||||
return getPathAfterLanguage()
|
||||
}
|
||||
return "";
|
||||
};
|
||||
return ''
|
||||
}
|
||||
|
||||
return {
|
||||
getPathAfterLanguage,
|
||||
getCurrentPath,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
import { templateRegistry } from "#layers/registry";
|
||||
export const useTemplateRegistry = () => templateRegistry;
|
||||
import { templateRegistry } from '#layers/registry'
|
||||
export const useTemplateRegistry = () => templateRegistry
|
||||
|
||||
Reference in New Issue
Block a user