feat: currentLocale.

This commit is contained in:
elforjani3
2021-06-10 14:56:10 +02:00
parent c66e86fbd5
commit 71c8adbbb8
2 changed files with 21 additions and 21 deletions

View File

@@ -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,17 +59,19 @@ 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 (