Search code examples
androidbuttonlocalizationrecordmonkeyrunner

Does MonkeyTalk support localization in Android?


When I record an action (for eg: button click) MonkeyTalk records the button text as a String so it doesnt work when I change the language on the device to non-English.

Eg: Button nein tap works fine in German language but doesn't work when I change the language to English.

Just want to know if there is any support in Monkey Talk to support localization or if there are any alternatives.


Solution

  • Solved it by getting all the fields for Android Resources

        Map<Integer, String> idMap = new HashMap<Integer, String>();
        Class<?> r;
        String rClass = "android.R$id";
        try {
            r = Class.forName(rClass);
        } catch (ClassNotFoundException e1) {
            Log.log("Unable to load " + rClass + ": " + e1.getMessage());
            return idMap;
        }
        for (Field f : r.getFields()) {
            int val;
            try {
                val = f.getInt(null);
            } catch (Exception e) {
                throw new IllegalStateException("Unable to get value for " + f.getName() + ": "
                        + e.getMessage());
            }
            idMap.put(val, f.getName());
    
        }