maeshinshin 1 год назад
Родитель
Сommit
cf89224171

+ 3 - 2
apps/app/src/pages/_app.page.tsx

@@ -1,6 +1,7 @@
 import type { ReactElement, ReactNode } from 'react';
 import type { ReactElement, ReactNode } from 'react';
 import React, { useEffect } from 'react';
 import React, { useEffect } from 'react';
 
 
+import type { Locale } from '@growi/core';
 import type { NextPage } from 'next';
 import type { NextPage } from 'next';
 import { appWithTranslation } from 'next-i18next';
 import { appWithTranslation } from 'next-i18next';
 import type { AppContext, AppProps } from 'next/app';
 import type { AppContext, AppProps } from 'next/app';
@@ -29,7 +30,7 @@ export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
 
 
 type GrowiAppProps = AppProps & {
 type GrowiAppProps = AppProps & {
   Component: NextPageWithLayout,
   Component: NextPageWithLayout,
-  userLocale: string,
+  userLocale: Locale,
 };
 };
 
 
 // register custom serializer
 // register custom serializer
@@ -77,7 +78,7 @@ function GrowiApp({ Component, pageProps, userLocale }: GrowiAppProps): JSX.Elem
 
 
 GrowiApp.getInitialProps = async(appContext: AppContext) => {
 GrowiApp.getInitialProps = async(appContext: AppContext) => {
   const appProps = App.getInitialProps(appContext);
   const appProps = App.getInitialProps(appContext);
-  const userLocale = getLocaleAtServerSide(appContext.ctx.req as unknown as CrowiRequest);
+  const userLocale = getLocaleAtServerSide(appContext.ctx.req as unknown as CrowiRequest) as Locale;
 
 
   return { ...appProps, userLocale };
   return { ...appProps, userLocale };
 };
 };

+ 2 - 1
apps/app/src/pages/_document.page.tsx

@@ -1,6 +1,7 @@
 /* eslint-disable @next/next/google-font-display */
 /* eslint-disable @next/next/google-font-display */
 import React from 'react';
 import React from 'react';
 
 
+import type { Locale } from '@growi/core';
 import type { DocumentContext, DocumentInitialProps } from 'next/document';
 import type { DocumentContext, DocumentInitialProps } from 'next/document';
 import Document, {
 import Document, {
   Html, Head, Main, NextScript,
   Html, Head, Main, NextScript,
@@ -43,7 +44,7 @@ interface GrowiDocumentProps {
   customCss: string | null,
   customCss: string | null,
   customNoscript: string | null,
   customNoscript: string | null,
   pluginResourceEntries: GrowiPluginResourceEntries;
   pluginResourceEntries: GrowiPluginResourceEntries;
-  locale: string;
+  locale: Locale;
 }
 }
 declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
 declare type GrowiDocumentInitialProps = DocumentInitialProps & GrowiDocumentProps;
 
 

+ 7 - 6
apps/app/src/pages/utils/commons.ts

@@ -1,5 +1,5 @@
-import type { ColorScheme, IUserHasId } from '@growi/core';
-import { Lang, AllLang, Locale } from '@growi/core';
+import type { ColorScheme, IUserHasId, Locale } from '@growi/core';
+import { Lang, AllLang } from '@growi/core';
 import { DevidedPagePath } from '@growi/core/dist/models';
 import { DevidedPagePath } from '@growi/core/dist/models';
 import { isServer } from '@growi/core/dist/utils';
 import { isServer } from '@growi/core/dist/utils';
 import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
 import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
@@ -110,10 +110,10 @@ export type LangMap = {
 };
 };
 
 
 export const langMap: LangMap = {
 export const langMap: LangMap = {
-  [Lang.ja_JP]: Locale['ja-JP'],
-  [Lang.en_US]: Locale['en-US'],
-  [Lang.zh_CN]: Locale['zh-CN'],
-  [Lang.fr_FR]: Locale['fr-FR'],
+  [Lang.ja_JP]: 'ja-JP' as Locale,
+  [Lang.en_US]: 'en-US' as Locale,
+  [Lang.zh_CN]: 'zh-CN' as Locale,
+  [Lang.fr_FR]: 'fr-FR' as Locale,
 };
 };
 
 
 // use this function to translate content
 // use this function to translate content
@@ -152,6 +152,7 @@ export const getNextI18NextConfig = async(
     namespaces.push('translation');
     namespaces.push('translation');
   }
   }
 
 
+  // The first argument must be a language code with an underscore, such as en_US
   return serverSideTranslations(lang, namespaces, nextI18NextConfig, preloadAllLang ? AllLang : false);
   return serverSideTranslations(lang, namespaces, nextI18NextConfig, preloadAllLang ? AllLang : false);
 };
 };
 
 

+ 2 - 8
packages/core/src/interfaces/locale.ts

@@ -1,8 +1,2 @@
-export const Locale = {
-  'en-US': 'en-US',
-  'ja-JP': 'ja-JP',
-  'zh-CN': 'zh-CN',
-  'fr-FR': 'fr-FR',
-} as const;
-export const AllLocale = Object.values(Locale);
-export type Locale = typeof Locale[keyof typeof Locale];
+export const AllLocale = ['en-US', 'ja-JP', 'zh-CN', 'fr-FR'];
+export type Locale = 'ja-JP' | 'en-US' | 'zh-CN' | 'fr-FR';