14

I have different strings.xml files in my resources folders (values, values_fr, values_de...), and I would like to load additional translations during runtime. Is it possible to add the new strings to those files even if it has already been compiled? Or is there a workaround?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hrk
  • 2,725
  • 5
  • 29
  • 44

1 Answers1

10

The simple answer is that you can't. You can't modify hard-coded stuff into APK resources.

But there are some options. For instance you can:

  • Let's say read a resource, modify it, and save it into another external folder (SD card or so)
  • Create AssetManager over those file(s)
  • Then create Resources which can be later used as ordinary Android resource stored in APK
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Barmaley
  • 16,638
  • 18
  • 73
  • 146
  • 1
    Ok, thanks! That seems to be what I need. Is it possible to load through "AssetManager" something else than XML ? For example JSON or formatted string ? – Hrk Jan 04 '11 at 14:09
  • I don't know about possibility to load JSON - sorry. – Barmaley Jan 05 '11 at 10:14
  • @Hrk: Yes it is. You can load anything you want as a raw stream from an asset: http://developer.android.com/reference/android/content/res/AssetManager.html#open(java.lang.String) – Robert Massaioli May 05 '11 at 02:35
  • 1
    Thank you barmaley but how do you do step 2? There is no constructor for AssetManager. Thanks in advance, Barry – Barry Fruitman Jun 21 '11 at 18:03
  • 1
    Turns out AssetManager does have a public constructor, but bizarrely it is not in the SDK docs. :( – Barry Fruitman Mar 17 '12 at 20:20