forked from geosolutions-it/MapStore2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8da0b98
commit 4b1e103
Showing
13 changed files
with
99 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2017, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
const PropTypes = require('prop-types'); | ||
const { castArray, isObject } = require('lodash'); | ||
const {getContext, mapProps, compose} = require('recompose'); | ||
|
||
const getLocalizedProp = (locale, prop) => isObject(prop) ? prop[locale] || prop.default : prop; | ||
|
||
const accumulate = (props, locale) => (acc = {}, propName) => ({ | ||
...acc, | ||
[propName]: props[propName] && getLocalizedProp(locale, props[propName]) | ||
}); | ||
/** | ||
* Converts the props indicated as arguments into localized strings checking if they are map of localized strings, like this: | ||
* ``` | ||
* { | ||
* "default": "TEST", | ||
* "en-US": "TEST en-US" | ||
* } | ||
* ``` | ||
* @name localizeStringMap | ||
* @memberof components.misc.enhancers | ||
* @param {string|[string]} propNames Name of the prop(s) to replace. can be an array or a single prop | ||
* @return {HOC} An HOC that replaces the prop string with localized string. | ||
* @example | ||
* const Input = localizeStringMap('title')(TitleBar); | ||
* // render | ||
* //... | ||
* <Input placeholder={{title}} /> | ||
*/ | ||
module.exports = (propNames) => compose( | ||
getContext({ | ||
locale: PropTypes.string | ||
}), | ||
mapProps(({locale, ...props}) => ({ | ||
...props, | ||
...(castArray(propNames).reduce(accumulate(props, locale), {})) | ||
}) | ||
)); |
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 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