Describe the bug
When reading a custom attribute for a custom view component we are using the TypedArray returned by Context#obtainStyledAttributes. This function is invoked on a PhilologyContextWrapper provided by Philology#wrap.
The current issue with this TypedArray instance is that its getString() function does not return a translated text. That's why we need the ViewTransformer#reword where we basically obtain the resource id of the String and reapply it on the view. And that's why the android framework also fails to set a translated text from a custom attribute(we've added the support in #27 but it's still handle this manually). This is handled currently by transformer package implementations for various components.
To Reproduce
Replace this reword implementation with:
private fun TextView.reword(attributeSet: AttributeSet) {
@StringRes val text =
context.obtainStyledAttributes(attributeSet, intArrayOf(android.R.attr.text)).getString(0)
@StringRes val hint =
context.obtainStyledAttributes(attributeSet, intArrayOf(android.R.attr.hint)).getString(0)
if (text.isNotEmpty()) setText(text)
if (hint.isNotEmpty) setHint(hint)
}
Run the sample and see the TextView components missing translations.
Expected behavior
The ideal case would be to help the framework use a correct TypedArray instance containing translated strings. This would help us get rid of ViewTransformer.reword, but this is the ideal case.
In order to ease the life of other teams would be nice to have a lint rule that will prohibit the usage of the TypedArray#getString() letting devs now that it will not return a translated text.
This should be a temporary solution while we search for a real fix.
Library version
v-2.1.0
Describe the bug
When reading a custom attribute for a custom view component we are using the
TypedArrayreturned by Context#obtainStyledAttributes. This function is invoked on a PhilologyContextWrapper provided by Philology#wrap.The current issue with this
TypedArrayinstance is that its getString() function does not return a translated text. That's why we need the ViewTransformer#reword where we basically obtain the resource id of the String and reapply it on the view. And that's why the android framework also fails to set a translated text from a custom attribute(we've added the support in #27 but it's still handle this manually). This is handled currently by transformer package implementations for various components.To Reproduce
Replace this reword implementation with:
Run the sample and see the
TextViewcomponents missing translations.Expected behavior
The ideal case would be to help the framework use a correct
TypedArrayinstance containing translated strings. This would help us get rid ofViewTransformer.reword, but this is the ideal case.In order to ease the life of other teams would be nice to have a lint rule that will prohibit the usage of the TypedArray#getString() letting devs now that it will not return a translated text.
This should be a temporary solution while we search for a real fix.
Library version
v-2.1.0