react-translate-component
Advanced tools
Comparing version 0.12.2 to 0.13.0
72
index.js
@@ -17,2 +17,7 @@ 'use strict'; | ||
var keyType = PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.arrayOf(PropTypes.string) | ||
]); | ||
var Translate = React.createClass({ | ||
@@ -22,3 +27,4 @@ displayName: 'Translate', | ||
contextTypes: { | ||
translator: translatorType | ||
translator: translatorType, | ||
scope: keyType | ||
}, | ||
@@ -29,13 +35,4 @@ | ||
count: PropTypes.number, | ||
content: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.arrayOf(PropTypes.string) | ||
]), | ||
scope: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.arrayOf(PropTypes.string) | ||
]), | ||
content: keyType, | ||
scope: keyType, | ||
attributes: PropTypes.object, | ||
@@ -87,3 +84,3 @@ with: PropTypes.object | ||
var attributeTranslationOptions = extend( | ||
{ locale: this.state.locale }, | ||
{ locale: this.state.locale, scope: this.context.scope }, | ||
props, | ||
@@ -102,5 +99,2 @@ interpolations, | ||
delete props.scope; | ||
delete props.separator; | ||
delete props.fallbackLocale; | ||
delete props.fallback; | ||
delete props.count; | ||
@@ -147,1 +141,47 @@ delete props.with; | ||
module.exports.translatorType = translatorType; | ||
module.exports.getLocale = translator.getLocale.bind(translator); | ||
module.exports.setLocale = translator.setLocale.bind(translator); | ||
module.exports.registerTranslations = translator.registerTranslations.bind(translator); | ||
function withTranslations(DecoratedComponent, translations) { | ||
if (!translations) { | ||
return function(decoratedComponent) { | ||
return withTranslations(decoratedComponent, DecoratedComponent); | ||
}; | ||
} | ||
var displayName = | ||
DecoratedComponent.displayName || | ||
DecoratedComponent.name || | ||
'Component'; | ||
for (var locale in translations) { | ||
var localeTranslations = translations[locale]; | ||
var scopedTranslations = {}; | ||
scopedTranslations[displayName] = localeTranslations; | ||
translator.registerTranslations(locale, scopedTranslations); | ||
} | ||
return React.createClass({ | ||
displayName: displayName + 'WithTranslations', | ||
childContextTypes: { | ||
scope: keyType | ||
}, | ||
getChildContext: function() { | ||
return { | ||
scope: displayName | ||
}; | ||
}, | ||
render: function() { | ||
return React.createElement(DecoratedComponent, this.props); | ||
} | ||
}); | ||
} | ||
module.exports.withTranslations = withTranslations; |
{ | ||
"name": "react-translate-component", | ||
"version": "0.12.2", | ||
"version": "0.13.0", | ||
"description": "A component for React that utilizes the counterpart module to translate/localize its content", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16011
140