WIP: Arabic localization.|

This commit is contained in:
a.bouhuolia
2021-06-10 12:51:00 +02:00
parent 4fc7c37260
commit 1ea32884c2
465 changed files with 3299 additions and 2109 deletions

View File

@@ -0,0 +1,80 @@
import React from 'react';
import intl from 'react-intl-universal';
import { find } from 'lodash';
import rtlDetect from 'rtl-detect';
import DashboardLoadingIndicator from 'components/Dashboard/DashboardLoadingIndicator';
const SUPPORTED_LOCALES = [
{ name: "English", value: "en" },
{ name: 'العربية', value: 'ar' }
];
/**
* Retrieve the current local.
*/
function getCurrentLocal() {
let currentLocale = intl.determineLocale({
urlLocaleKey: "lang",
cookieLocaleKey: "lang",
localStorageLocaleKey: "lang",
});
if (!find(SUPPORTED_LOCALES, { value: currentLocale })) {
currentLocale = "en";
}
return currentLocale;
}
/**
* Loads the localization data of the given locale.
*/
function loadLocales(currentLocale) {
return import(`../lang/${currentLocale}/index.json`);
}
/**
* Modifies the html document direction to RTl if it was rtl-language.
*/
function useDocumentDirectionModifier(locale) {
React.useEffect(() => {
const isRTL = rtlDetect.isRtlLang(locale);
if (isRTL) {
const htmlDocument = document.querySelector('html');
htmlDocument.setAttribute('dir', 'rtl');
htmlDocument.setAttribute('lang', locale);
}
}, []);
}
/**
* Application Intl loader.
*/
export default function AppIntlLoader({
children
}) {
const [isLoading, setIsLoading] = React.useState(true);
const currentLocale = getCurrentLocal();
// Modifies the html document direction
useDocumentDirectionModifier(currentLocale);
React.useEffect(() => {
// Lodas the locales data file.
loadLocales(currentLocale).then((results) => {
return intl.init({
currentLocale,
locales: {
[currentLocale]: results,
},
});
}).then(() => {
setIsLoading(false);
});
}, [currentLocale, setIsLoading]);
return (
<DashboardLoadingIndicator isLoading={isLoading}>
{children}
</DashboardLoadingIndicator>
);
}