Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all the strings in strings.xml

In my app, for localization I have a values-ar folder for arabic strings. The problem is that the arabic alphabet appears unconnected in phones which do not have Arabic language installed. I'm using the ArabicReshape class to join the arabic alphabets but since I have too many strings, I cannot manually keep applying the reshaper class one by one.

I would like to know if I can get all the strings from the strings.xml file and apply the class to the strings at one go by looping through them. Is this possible?

like image 604
input Avatar asked Dec 26 '22 11:12

input


1 Answers

I don't understand why you need to iterate thrtough ALL strings instead of calling the class when you need one specific string.

But as you asked...

I guess this might help you ;-)

Field[] fields = R.string.class.getFields();
    for(final Field field : fields) {
       String name = field.getName(); //name of string
       try{
           int id = field.getInt(R.string.class); //id of string
       }catch (Exception ex) {
           //do smth
       }
    }
like image 121
Waza_Be Avatar answered Jan 06 '23 05:01

Waza_Be