0

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 Answers1

0

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.

yazantahhan
  • 2,950
  • 1
  • 13
  • 16
  • Thank you. Yes I would need iOS too, so will check out the plugin you have mentioned. Have a doubt in it, how do I refer the variables defined in the json file in my HTML? For e.g. if I have PAGE_TITLE in my json file, how do I get its value in my HTML/ – user12343088 Nov 09 '19 at 13:19
  • I'm sorry about the wrong Cordova plugin. This plugin actually used for native strings. Check my updated answer – yazantahhan Nov 09 '19 at 13:48
  • After checking both options, the localization plugin is what seems best suited to my requirement. But I am still stuck at the core issue of how to access the strings defined in .json (which are then pushed into the plist and strings.xml files) in my cordova code. – user12343088 Nov 11 '19 at 03:45