mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: currentLocale.
This commit is contained in:
@@ -6,8 +6,8 @@ import rtlDetect from 'rtl-detect';
|
|||||||
import DashboardLoadingIndicator from 'components/Dashboard/DashboardLoadingIndicator';
|
import DashboardLoadingIndicator from 'components/Dashboard/DashboardLoadingIndicator';
|
||||||
|
|
||||||
const SUPPORTED_LOCALES = [
|
const SUPPORTED_LOCALES = [
|
||||||
{ name: "English", value: "en" },
|
{ name: 'English', value: 'en' },
|
||||||
{ name: 'العربية', value: 'ar' }
|
{ name: 'العربية', value: 'ar-ly' },
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,12 +15,12 @@ const SUPPORTED_LOCALES = [
|
|||||||
*/
|
*/
|
||||||
function getCurrentLocal() {
|
function getCurrentLocal() {
|
||||||
let currentLocale = intl.determineLocale({
|
let currentLocale = intl.determineLocale({
|
||||||
urlLocaleKey: "lang",
|
urlLocaleKey: 'lang',
|
||||||
cookieLocaleKey: "lang",
|
cookieLocaleKey: 'lang',
|
||||||
localStorageLocaleKey: "lang",
|
localStorageLocaleKey: 'lang',
|
||||||
});
|
});
|
||||||
if (!find(SUPPORTED_LOCALES, { value: currentLocale })) {
|
if (!find(SUPPORTED_LOCALES, { value: currentLocale })) {
|
||||||
currentLocale = "en";
|
currentLocale = 'en';
|
||||||
}
|
}
|
||||||
return currentLocale;
|
return currentLocale;
|
||||||
}
|
}
|
||||||
@@ -50,9 +50,7 @@ function useDocumentDirectionModifier(locale) {
|
|||||||
/**
|
/**
|
||||||
* Application Intl loader.
|
* Application Intl loader.
|
||||||
*/
|
*/
|
||||||
export default function AppIntlLoader({
|
export default function AppIntlLoader({ children }) {
|
||||||
children
|
|
||||||
}) {
|
|
||||||
const [isLoading, setIsLoading] = React.useState(true);
|
const [isLoading, setIsLoading] = React.useState(true);
|
||||||
const currentLocale = getCurrentLocal();
|
const currentLocale = getCurrentLocal();
|
||||||
|
|
||||||
@@ -61,22 +59,24 @@ export default function AppIntlLoader({
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Lodas the locales data file.
|
// Lodas the locales data file.
|
||||||
loadLocales(currentLocale).then((results) => {
|
loadLocales(currentLocale)
|
||||||
return intl.init({
|
.then((results) => {
|
||||||
currentLocale,
|
return intl.init({
|
||||||
locales: {
|
currentLocale,
|
||||||
[currentLocale]: results,
|
locales: {
|
||||||
},
|
[currentLocale]: results,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
moment.locale(currentLocale);
|
||||||
|
setIsLoading(false);
|
||||||
});
|
});
|
||||||
}).then(() => {
|
|
||||||
moment.locale('ar-ly');
|
|
||||||
setIsLoading(false);
|
|
||||||
});
|
|
||||||
}, [currentLocale, setIsLoading]);
|
}, [currentLocale, setIsLoading]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardLoadingIndicator isLoading={isLoading}>
|
<DashboardLoadingIndicator isLoading={isLoading}>
|
||||||
{children}
|
{children}
|
||||||
</DashboardLoadingIndicator>
|
</DashboardLoadingIndicator>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user