This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/localisation #9
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import './App.css'; | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import './App.css' | ||
import 'antd/dist/antd.css' | ||
import './css/style.css' | ||
import Routes from './routes/index' | ||
import store from './store/store' | ||
import { setLocale } from './modules/Authentication/store/actions'; | ||
import { setLocale } from './modules/Authentication/store/actions' | ||
|
||
/**import i18next configs when app starts */ | ||
import './i18n' | ||
store.dispatch(setLocale('en')) | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<Provider store={store}> | ||
<Routes/> | ||
</Provider> | ||
</div> | ||
); | ||
return ( | ||
<div className="App"> | ||
<Provider store={store}> | ||
<Routes /> | ||
</Provider> | ||
</div> | ||
) | ||
} | ||
|
||
export default App; | ||
export default App |
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,23 @@ | ||
import i18n from 'i18next' | ||
import { initReactI18next } from 'react-i18next' | ||
|
||
/*Supported Langs */ | ||
const resources = { | ||
en: { | ||
translation: require('./localisations/en.json'), | ||
}, | ||
ar: { | ||
translation: require('./localisations/ar.json'), | ||
}, | ||
} | ||
/**Config i18next */ | ||
i18n.use(initReactI18next) // passes i18n down to react-i18next | ||
.init({ | ||
resources, | ||
lng: localStorage.getItem('appLang'), | ||
fallbackLng: 'en', | ||
//keySeparator: false, // we do not use keys in form messages.welcome | ||
interpolation: { | ||
escapeValue: false, // react already safes from xss | ||
}, | ||
}) |
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,11 @@ | ||
{ | ||
"ChangeLang": "تغير اللغة", | ||
"register": { | ||
"Email": "البريد الاليكترونى", | ||
"Password": "كلمة السر", | ||
"rePassword": "اعد كتابة كلمة السر", | ||
"wrongPass": "كلمة السر غير مطابقة", | ||
"Register": "تسجيل", | ||
"Login": "مستخدم سابق؟ قم بتسدخيل دخول" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"ChangeLang": "Change Language", | ||
"register": { | ||
"Email": "Email", | ||
"Password": "Password", | ||
"rePassword": "Rewrite Your Password", | ||
"wrongPass": "Password Mismatch", | ||
"Register": "Register", | ||
"Login": "Already have An Account ? Login" | ||
} | ||
} |
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,50 @@ | ||
import React from 'react' | ||
import { Button, Form, Input, Alert, Dropdown, Menu } from 'antd' | ||
import { useTranslation } from 'react-i18next' | ||
/**Component Wrapper for locals */ | ||
const Create = (props) => { | ||
const { t, i18n } = useTranslation() | ||
/**array of Locals */ | ||
const getSupportedLocals = () => ['ar', 'en'] | ||
/**current Active Lang */ | ||
const getCurrentLang = () => i18n.language | ||
/**localise by key */ | ||
const trans = (key) => t(key) | ||
/**change lang by key */ | ||
const changeLang = (key) => { | ||
i18n.changeLanguage(key).then(() => { | ||
localStorage.setItem('appLang', getCurrentLang()) | ||
}) | ||
} | ||
/**returns dropdown of supported languages for change */ | ||
const getChangeLangDropDown = () => { | ||
const locals = getSupportedLocals() | ||
const localsItems = () => ( | ||
<Menu> | ||
{locals.map((v, k) => ( | ||
<Menu.Item key={k}> | ||
<Button type="link" onClick={() => changeLang(v)}> | ||
{trans(v)} | ||
</Button> | ||
</Menu.Item> | ||
))} | ||
</Menu> | ||
) | ||
return ( | ||
<Dropdown overlay={localsItems()} trigger={['hover']}> | ||
<a className="ant-dropdown-link" href="#"> | ||
{trans('ChangeLang')} | ||
</a> | ||
</Dropdown> | ||
) | ||
} | ||
|
||
return { | ||
trans, | ||
changeLang, | ||
getSupportedLocals, | ||
getChangeLangDropDown, | ||
} | ||
} | ||
|
||
export default { Create } |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly, fix the following typo:
I'm not sure about
الاليكتروني
and usingالمرور
instead ofالسر