mirror of
https://github.com/zuiidea/antd-admin.git
synced 2026-10-19 16:14:37 +00:00
✨ Support disable i18n.
This commit is contained in:
@@ -60,9 +60,9 @@ export default {
|
||||
},
|
||||
pwa: {
|
||||
manifestOptions: {
|
||||
srcPath: 'manifest.json'
|
||||
srcPath: 'manifest.json',
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
@@ -26,7 +26,7 @@ class Layout extends Component {
|
||||
componentDidMount() {
|
||||
const language = langFromPath(this.props.location.pathname)
|
||||
this.language = language
|
||||
this.loadCatalog(language)
|
||||
language && this.loadCatalog(language)
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
@@ -35,7 +35,7 @@ class Layout extends Component {
|
||||
const { catalogs } = nextState
|
||||
|
||||
if (preLanguage !== language && !catalogs[language]) {
|
||||
this.loadCatalog(language)
|
||||
language && this.loadCatalog(language)
|
||||
this.language = language
|
||||
return false
|
||||
}
|
||||
|
||||
+35
-17
@@ -10,8 +10,10 @@ export config from './config'
|
||||
export request from './request'
|
||||
export { Color } from './theme'
|
||||
|
||||
export const { defaultLanguage } = i18n
|
||||
export const languages = i18n.languages.map(item => item.key)
|
||||
// export const { defaultLanguage } = i18n
|
||||
// export const languages = i18n.languages.map(item => item.key)
|
||||
export const languages = i18n ? i18n.languages.map(item => item.key) : []
|
||||
export const defaultLanguage = i18n ? i18n.defaultLanguage : ''
|
||||
|
||||
/**
|
||||
* Query objects that specify keys and values in an array where all values are objects.
|
||||
@@ -61,23 +63,32 @@ export function arrayToTree(
|
||||
return result
|
||||
}
|
||||
|
||||
export const langFromPath = curry(
|
||||
/**
|
||||
* Query language from pathname.
|
||||
* @param {array} languages Specify which languages are currently available.
|
||||
* @param {string} defaultLanguage Specify the default language.
|
||||
* @param {string} pathname Pathname to be queried.
|
||||
* @return {string} Return the queryed language.
|
||||
*/
|
||||
(languages, defaultLanguage, pathname) => {
|
||||
for (const item of languages) {
|
||||
if (pathname.startsWith(`/${item}/`)) {
|
||||
return item
|
||||
}
|
||||
// export const langFromPath = curry(
|
||||
// /**
|
||||
// * Query language from pathname.
|
||||
// * @param {array} languages Specify which languages are currently available.
|
||||
// * @param {string} defaultLanguage Specify the default language.
|
||||
// * @param {string} pathname Pathname to be queried.
|
||||
// * @return {string} Return the queryed language.
|
||||
// */
|
||||
// (languages, defaultLanguage, pathname) => {
|
||||
// for (const item of languages) {
|
||||
// if (pathname.startsWith(`/${item}/`)) {
|
||||
// return item
|
||||
// }
|
||||
// }
|
||||
// return defaultLanguage
|
||||
// }
|
||||
// )(languages)(defaultLanguage)
|
||||
|
||||
export const langFromPath = pathname => {
|
||||
for (const item of languages) {
|
||||
if (pathname.startsWith(`/${item}/`)) {
|
||||
return item
|
||||
}
|
||||
return defaultLanguage
|
||||
}
|
||||
)(languages)(defaultLanguage)
|
||||
return defaultLanguage
|
||||
}
|
||||
|
||||
export const deLangPrefix = curry(
|
||||
/**
|
||||
@@ -106,11 +117,18 @@ export const deLangPrefix = curry(
|
||||
* @return {string} Return the pathname after adding the language prefix.
|
||||
*/
|
||||
export function addLangPrefix(pathname) {
|
||||
if (!i18n) {
|
||||
return pathname
|
||||
}
|
||||
|
||||
const prefix = langFromPath(window.location.pathname)
|
||||
return `/${prefix}${deLangPrefix(pathname)}`
|
||||
}
|
||||
|
||||
const routerAddLangPrefix = params => {
|
||||
if (!i18n) {
|
||||
return params
|
||||
}
|
||||
if (isString(params)) {
|
||||
params = addLangPrefix(params)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user