-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(framework): Add dynamic language change and on-demand rerendering (
- Loading branch information
1 parent
33fa055
commit 1b568f2
Showing
38 changed files
with
269 additions
and
71 deletions.
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
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
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
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,12 +1,41 @@ | ||
import { getLanguage as getConfiguredLanguage } from "../InitialConfiguration.js"; | ||
import { fireLanguageChange } from "../locale/languageChange.js"; | ||
import RenderScheduler from "../RenderScheduler.js"; | ||
|
||
let language; | ||
|
||
/** | ||
* Returns the currently configured language, or the browser language as a fallback | ||
* @returns {String} | ||
*/ | ||
const getLanguage = () => { | ||
if (language === undefined) { | ||
language = getConfiguredLanguage(); | ||
} | ||
return language; | ||
}; | ||
|
||
export { getLanguage }; // eslint-disable-line | ||
/** | ||
* Changes the current language, re-fetches all message bundles, updates all language-aware components | ||
* and returns a promise that resolves when all rendering is done | ||
* | ||
* @param newLanguage | ||
* @returns {Promise<void>} | ||
*/ | ||
const setLanguage = async newLanguage => { | ||
if (language === newLanguage) { | ||
return; | ||
} | ||
|
||
language = newLanguage; | ||
|
||
const listenersResults = fireLanguageChange(newLanguage); | ||
await Promise.all(listenersResults); | ||
RenderScheduler.reRenderAllUI5Elements({ languageAware: true }); | ||
return RenderScheduler.whenFinished(); | ||
}; | ||
|
||
export { | ||
getLanguage, | ||
setLanguage, | ||
}; |
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,14 @@ | ||
const rtlAwareSet = new Set(); | ||
|
||
const markAsRtlAware = klass => { | ||
rtlAwareSet.add(klass); | ||
}; | ||
|
||
const isRtlAware = klass => { | ||
return rtlAwareSet.has(klass); | ||
}; | ||
|
||
export { | ||
markAsRtlAware, | ||
isRtlAware, | ||
}; |
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,15 @@ | ||
import RenderScheduler from "../RenderScheduler.js"; | ||
|
||
/** | ||
* Re-renders all RTL-aware UI5 Elements. | ||
* Call this method whenever you change the "dir" property anywhere in your HTML page | ||
* Example: document.body.dir = "rtl"; applyDirection(); | ||
* | ||
* @returns {Promise<void>} | ||
*/ | ||
const applyDirection = () => { | ||
RenderScheduler.reRenderAllUI5Elements({ rtlAware: true }); | ||
return RenderScheduler.whenFinished(); | ||
}; | ||
|
||
export default applyDirection; |
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,22 @@ | ||
import EventProvider from "../EventProvider.js"; | ||
|
||
const eventProvider = new EventProvider(); | ||
const LANG_CHANGE = "languageChange"; | ||
|
||
const attachLanguageChange = listener => { | ||
eventProvider.attachEvent(LANG_CHANGE, listener); | ||
}; | ||
|
||
const detachLanguageChange = listener => { | ||
eventProvider.detachEvent(LANG_CHANGE, listener); | ||
}; | ||
|
||
const fireLanguageChange = lang => { | ||
return eventProvider.fireEvent(LANG_CHANGE, lang); | ||
}; | ||
|
||
export { | ||
attachLanguageChange, | ||
detachLanguageChange, | ||
fireLanguageChange, | ||
}; |
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,10 @@ | ||
// This is needed as IE11 doesn't have Set.prototype.keys/values/entries, so [...mySet.values()] is not an option | ||
const setToArray = s => { | ||
const arr = []; | ||
s.forEach(item => { | ||
arr.push(item); | ||
}); | ||
return arr; | ||
}; | ||
|
||
export default setToArray; |
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
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
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
Oops, something went wrong.