Android and iOS cross-platform string resources (MonoTouch & MonoDroid)

1.5k Views Asked by At

I'm busy with a cross-platform mobile app using the Xamarin mono libraries and I ran into the following situation...

I've got a bunch of string resources in my monodroid project (strings.xml) that are being used by my layouts and my C# code.

What I would like to to is to move these string resources to a file in a shared project so that both iOS, Android and Windows phone will be able to use them. What is the best way to achieve this?

*Currently i'm using a Resource.resx file that contains the non-UI strings. And then I have the strings.xml file in the android(monodroid) project to cater for the UI resource strings.

Keep the following in mind:

  • The same file must be used by all the platforms.
  • I need the android layouts to also use the same resources. (which currently is the strings.xml file)
  • It should preferably be one file.

Any opinions?

2

There are 2 best solutions below

0
On

Another option would be to use a generator to generate the appropriate resources at build time. For simplicity, I decided to create a Resource Migrator that I run with every build.

Essentially, I take everything in my PCL's *.resx files, and generate Android or iOS resources before building the app. This is a similar approach to combining/minifying CSS/JS in a web application during build time... it reduces performance overhead at runtime.

0
On

There are (at least) a couple of 'standard' libraries/tools you could look at:

Both of those are open source - you should be able to make your own design-time or run-time tools out from those.