B3nedikt / reword

Reword is a android library to update the texts of views when the apps texts have changed due to a language change or an update of the apps string resources.
Apache License 2.0
32 stars 7 forks source link

Unable to reword strings of bottomNavigationMenu #12

Closed ashu5398 closed 3 years ago

ashu5398 commented 3 years ago

Hi, I am unable to change the strings inflated in bottom Navigation Menu. Here is my code of bottomNavigationMenu. Is there anything I am missing on my end?

<com.google.android.material.bottomnavigation.BottomNavigationView            
            android:id="@+id/bottomNav"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:labelVisibilityMode="labeled"
            android:background="#fff"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/menu_home" />
B3nedikt commented 3 years ago

The BottomNavigtaionView is supported out of the box, as this lib contains a ViewTransfomer for it. I just integrated a BottomNavigationView into my sample app and everything works fine there.

Your code above looks correct, you may try to recreate the issue by forking my sample app and integrate your BottomNavigationView in the same way as in your real app. If this does not recreate the issue it may be due to something specific for your app. It may also depend on some specific version of the material lib or other libs used in your project.

ashu5398 commented 3 years ago

Oh Thanks!! I got the issue, I have not defined the id's for menu items. Also Just want to know one thing, the same way we are transforming the BottomNavigationMenu items, can we transform the menu items of the toolbar/support toolbar, so that strings of popup menu also got translated easily. As PopupMenu does not extends View we can not make its transformer directly, Or is there any other way to update popup menu strings?

B3nedikt commented 3 years ago

You're welcome :) Yes, it should work the same way with Toolbar/support Toolbar as with the BottomNavigationItems.

Basically something like this in the ToolbarViewTransformer:

    override fun Toolbar.transform(attrs: Map<String, Int>) {
        attrs.forEach { entry ->
            when (entry.key) {
                ATTRIBUTE_TITLE, ATTRIBUTE_ANDROID_TITLE -> updateTexts(entry.value, this::setTitle)
                ATTRIBUTE_SUBTITLE, ATTRIBUTE_ANDROID_SUBTITLE -> updateTexts(entry.value, this::setSubtitle)
                SOME_ATTRIBUTE -> menu.getItem(...).setTitle()
            }
        }
    }

I don't have the time to look into this at the moment, but maybe in the next weeks, this would definitely be a good improvement for the lib. If you want the feature now you can implement it though and create a PR :)

ashu5398 commented 3 years ago

PR added with the update: https://github.com/B3nedikt/reword/pull/14 :)

B3nedikt commented 3 years ago

@ashu5398 Released as version 2.1.0, thanks for the contribution :)