Cordova Hybrid Mobile App - How do I access the value of a resource specified in strings.xml in my index.html page

265 Views Asked by At

I am a newbie to Hybrid mobile app development and am using Cordova. I have created a simple app with index.html and related .js and .css files. Now I have added a resource string 'pagetitle' in strings.xml and I need to retrieve the value and display it in HTML. Any pointers in this regard would be greatly appreciated.

I have worked on native app Android development and have accessed resources from strings.xml, for e.g. in my case it would be '@string/pagetitle'. But now since I am developing a hybrid app and have only HTML, CSS, JS to develop.

1

There are 1 best solutions below

3
On

Update

It seems that the plugin is used for the native part as explained here:

This plugin helps you to manage string files that you need natively, namely on Localizable.strings and InfoPlist.strings on iOS, and strings.xml on Android.

So for the i18n, you will need external library like LocalePlanet whci you can use like this: _('Hello, world!')


Old Answer

No need to add it in the strings.xml. Just use the string as it is. If you add it there, then the iOS won't work properly. example: `My Page Name

If you still want to support the i18n, then you can check this Cordova plugin. But instead of string.xml, it will be from json file.