-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump decompress from 4.0.0 to 4.2.1 (#94) Bumps [decompress](https://github.com/kevva/decompress) from 4.0.0 to 4.2.1. - [Release notes](https://github.com/kevva/decompress/releases) - [Commits](kevva/decompress@v4.0.0...v4.2.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * SEEXT-8959 Update cli settings page template * Update settings page templates * Switch to preinstall * Remove excess translation, adjust developer name source * Cleanup and add developer to context when creating page * Resolve translation and style issues * Fix dependencies and use PureComponent * Clean up imports * Fix package.json and use prepare instead of preinstall * Rename extension-page to shortcut-page in shortcut template * Version bump, switch to preinstall for testing * Replace Component with PureComponent * Feature/remove en json and add messaging and example (#103) * Add examples and remove en.json * Adjust messaging for page add * Add missing 'and' * Switch to prepare Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
62a9107
commit 8ddb433
Showing
36 changed files
with
462 additions
and
293 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
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 was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/templates/settings-page-react-bin/server/bin/localization/LocalizationProvider.js
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,108 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import i18next from 'i18next'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import _ from 'lodash'; | ||
import { connect } from 'react-redux'; | ||
import { LoaderContainer } from '@shoutem/react-web-ui'; | ||
import translation from '../../translations/en.json'; | ||
|
||
export class LocalizationProvider extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.handleInjection = this.handleInjection.bind(this); | ||
|
||
this.state = { | ||
inProgress: true, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const { ownExtensionName, locale, translationUrl } = this.props; | ||
const dictionary = _.get(translation, ownExtensionName); | ||
|
||
i18next.use(initReactI18next).init({ | ||
lng: 'en', | ||
fallbackLng: 'en', | ||
ns: [ownExtensionName], | ||
defaultNS: ownExtensionName, | ||
nsSeparator: false, | ||
keySeparator: false, | ||
resources: { | ||
en: { | ||
[ownExtensionName]: dictionary, | ||
}, | ||
}, | ||
}); | ||
|
||
this.handleInjection(locale, translationUrl); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const { | ||
locale: nextLocale, | ||
translationUrl: nextTranslationUrl, | ||
} = nextProps; | ||
const { locale, translationUrl } = this.props; | ||
|
||
if (translationUrl !== nextTranslationUrl || nextLocale !== locale) { | ||
this.handleInjection(nextLocale, nextTranslationUrl); | ||
} | ||
} | ||
|
||
async handleInjection(locale, translationUrl) { | ||
const { ownExtensionName } = this.props; | ||
|
||
if (translationUrl) { | ||
try { | ||
const response = await fetch(translationUrl); | ||
const translation = await response.json(); | ||
const dictionary = _.get(translation, ownExtensionName); | ||
|
||
if (dictionary) { | ||
await i18next.addResourceBundle(locale, ownExtensionName, dictionary); | ||
await i18next.changeLanguage(locale); | ||
} | ||
} catch (error) { | ||
// do nothing | ||
} | ||
} | ||
|
||
this.setState({ inProgress: false }); | ||
} | ||
|
||
render() { | ||
const { children } = this.props; | ||
const { inProgress } = this.state; | ||
|
||
if (inProgress) { | ||
return <LoaderContainer size="50px" isLoading />; | ||
} | ||
|
||
return children; | ||
} | ||
} | ||
|
||
LocalizationProvider.propTypes = { | ||
children: PropTypes.node, | ||
ownExtensionName: PropTypes.string, | ||
locale: PropTypes.string, | ||
translationUrl: PropTypes.string, | ||
}; | ||
|
||
function mapStateToProps(state, ownProps) { | ||
const { context } = ownProps; | ||
|
||
const ownExtensionName = _.get(context, 'ownExtensionName'); | ||
const locale = _.get(context, 'i18n.locale'); | ||
const translationUrl = _.get(context, 'i18n.translationUrl'); | ||
|
||
return { | ||
ownExtensionName, | ||
locale, | ||
translationUrl, | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(LocalizationProvider); |
1 change: 1 addition & 0 deletions
1
src/templates/settings-page-react-bin/server/bin/localization/index.js
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 @@ | ||
export { default as LocalizationProvider } from './LocalizationProvider'; |
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.