Get all strings in strings.xml

In my localization application, I have a values-ar folder for arabic strings. The problem is that the Arabic alphabet is not connected to phones that do not have Arabic installed. I use the ArabReshape class to join the Arabic alphabets, but since I have too many lines, I cannot manually continue to apply the reshaper class one by one.

I would like to know if I can get all the lines from the strings.xml file and apply the class to the lines in one pass, going through them. Is it possible?

+4
source share
2 answers

I do not understand why you need to repeat ALL lines, instead of calling the class when you need one specific line.

But as you asked ...

I think this may 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 } } 
+6
source

What you need to do is set LOCALE to AR so that the resource manager allows you to pull the string from the values โ€‹โ€‹of-ar / strings.xml and then get the Field list using reflection R.string.class.getFields () . Then iterate over your lines and do a redo.

Try something like the following code snippet:

 Resources resources = getResources(); int resourceId = 0; String resourceString; Field[] stringFields = R.string.class.getFields(); for(Field stringField : stringFields) { try { resourceId = stringField.getInt(R.string.class); } catch (IllegalArgumentException e) { e.printStackTrace(); continue; } catch (IllegalAccessException e) { e.printStackTrace(); continue; } resourceString = resources.getString(resourceId); if(resourceString != null && resourceString.length() > 0) { // do your reshaping on the resoureString } } 
+1
source

All Articles