0

I am trying the understand the internal workings of R.java and localization in Android.I know that the strings are compile time resources and are generated by the apt. I have several questions regarding R.java .

1.If I open the R.java generated file I can see

public final class R {
public static final class string {
    public static final int HelloMessage=0x7f05000f;
}

Why is R.String.HelloMessage is int.And if it's static final how the localized version works with the same int as I cannot see any localized version of the variable.

2.How the switching to locales happen.Can someone point me to the android source code.I have browsed the code for android.content.res.AssetManager,com.android .settings.LocalePicker.java but I am not sure how behind the scene R.Java is loading the localized strings.

Thanks

Crypt
  • 189
  • 1
  • 4
  • 13

1 Answers1

1

Android is retrieving the locale of the device and then chooses the strings from the right folder. It can do so because the localized strings are in folders with a specific naming convention. The Ids of the same strings are all the same in every different folder... it just has to choose it in the right folder based on the locale of the device as I said...

one way how you can do so is explained in another SO thread : Android get device locale

Community
  • 1
  • 1
Ilja KO
  • 1,272
  • 12
  • 26
  • Thanks for the reply.But I am trying to find out more in terms of how Android is implementing this.I am digging into the source code of android for this.But I am not able to trace it after Resources.updateConfiguration() and AssetManager.setConfiguration() – Crypt Nov 30 '15 at 06:35