-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/next' into fix/optimize-route-config
- Loading branch information
Showing
18 changed files
with
157 additions
and
42 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './esm/runtime-simple'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const EXPORT_NAME = 'locale'; | ||
|
||
export const getDefaultLocale = () => { | ||
// @ts-ignore | ||
const defaultLocale = (typeof window !== 'undefined' && window.__ICE_DEFAULT_LOCALE__) || | ||
(typeof navigator !== 'undefined' && navigator.language) || | ||
'zh-CN'; | ||
return defaultLocale.replace('_', '-'); | ||
}; | ||
|
||
export const getLocaleMessages = () => { | ||
// @ts-ignore | ||
const localeMessages = typeof window === 'undefined' ? global.__ICE_LOCALE_MESSAGES__ : window.__ICE_LOCALE_MESSAGES__; | ||
return localeMessages || {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { RuntimePlugin } from '@ice/runtime/types'; | ||
import { getDefaultLocale, getLocaleMessages, EXPORT_NAME } from './intl-until.js'; | ||
|
||
let currentLocale = getDefaultLocale(); | ||
let localeMessages = getLocaleMessages(); | ||
|
||
const runtime: RuntimePlugin = async ({ | ||
appContext, | ||
}) => { | ||
const { appExport } = appContext; | ||
const { getLocale, ...l } = appExport?.[EXPORT_NAME] || {}; | ||
if (Object.keys(l)?.length > 0) { | ||
console.error('The locale config is not supported in the simple mode.'); | ||
} | ||
const locale = getLocale ? getLocale() : getDefaultLocale(); | ||
currentLocale = locale; | ||
// Refresh locale messages for server side because of import hoisting. | ||
localeMessages = getLocaleMessages(); | ||
}; | ||
|
||
interface MessageDescriptor { | ||
id: string; | ||
defaultMessage?: string; | ||
} | ||
|
||
const intl = { | ||
formatMessage: (message: MessageDescriptor | string, values?: Record<string, string>) => { | ||
let messageId = typeof message === 'string' ? message : message.id; | ||
const defaultMessage = typeof message === 'string' ? message : message.defaultMessage; | ||
let content = localeMessages?.[currentLocale]?.[messageId]; | ||
if (!content) { | ||
console.error(`Message with id "${messageId}" not found in locale "${currentLocale}"`); | ||
return defaultMessage || messageId; | ||
} | ||
if (values) { | ||
Object.keys(values).forEach((key) => { | ||
content = content.replace(new RegExp(`{${key}}`, 'g'), values[key]); | ||
}); | ||
} | ||
return content; | ||
}, | ||
}; | ||
|
||
export { intl }; | ||
|
||
export default runtime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters