-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Right now, at least from looking at the source, I think there's no clean way to access attributes when using getString via withLocalization.
Would it be too ugly to change getString so that it can also (optionally) return formatted attributes?
I'm asking because I want to have the following setup:
Having this as input:
MyReactComponent =
.label1 = Label 1
.btn-allow = allow
.btn-deny = deny
I want to be able to use it like this:
class MyReactComponent extends Component {
render() {
return <button>{this.props.getAttribute("btn-allow")}</button>;
}
}
customLocalization(MyReactComponent);customLocalization would be a HOC that stores the wrapped component name
(MyReactComponent) and exposes the getAttribute function:
getAttribute(attrId, args, fallback) {
return this.props.getString(wrappedComponentName, args, fallback, [attrId]);
}The reason I want do to that is to avoid having to repeat component names in the translation files (e.g.: MyReactComponent-label1, MyReactComponent-btn-allow, etc.)
I could submit a pull request to change getString in the way I'm proposing, but before I do that I want to know if this too much of a corruption of the original design and shouldn't be done at all, or if I'm missing something and this is already possible.