EddyVerbruggen / nativescript-localize

Internationalization plugin for NativeScript using native capabilities of each platform
MIT License
79 stars 31 forks source link

Notifications fail to localize due to resource keys being encoded. #18

Closed spstratis closed 6 years ago

spstratis commented 6 years ago

First off just want to say, great job with this plugin and keeping it maintained. I seem to have a found an issue being caused due to the the resource keys being encoded rather than using the value from the json files.

When sending push notifications from a notification server, if you want to localize the notification, you can point to resource keys in the apps resource files in the message body using title_loc_key and the app will pick it up when it displays the notification. Here is an example:

Curl request to send a test push notification

curl -X POST --header "Authorization:key=AAAAR*************aHT" --Header "Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d "{  
   "notification":{  
      "title_loc_key":"someResourceKey",
      "text":"My text",
      "badge":"1",
      "sound":"default"
   },
   "priority":"High",
   "to":   "dqIeO*****relj3k}"

Unfortunately, this fails due to the generated resource key not using the key name that I put in the language JSON file.

en.json "someResourceKey":"some string",

generated localizable.string "_0419cd6075559fa33e0c6619358e25d22c87ccfb" :"some string";

If I place the encoded key into the notification payload then it works. This doesn't feel like the right approach though, the encoded string isn't developer friendly to read and makes it difficult to use when needing to be referenced in a service. There is also no guarantee that the encoded string will remain consistent when a rebuild occurs.

Do you all have plans to fix this issue? I'm not sure what the motivation is to use encoded keys in the plugin.

Thanks!

lfabreges commented 6 years ago

Hi,

Thanks for the report, for now the encoded key remains the same as long as you don't change the key in your JSON file. All keys are encoded so that you don't have to bother if the key is a valid resource name for Android or a valid key for iOS.

I think I'll encode keys only if it doesn't match /^[a-zA-Z_][a-zA-Z0-9_.]$/.

Regards.

spstratis commented 6 years ago

Thanks for the quick response. Looking forward to your update!

lfabreges commented 6 years ago

I'll publish a new version this evening, keys will be more user friendly but still encoded so that users don't have to worry about a key being unique and valid on both Android and iOS.

spstratis commented 6 years ago

Great! Look forward to trying it out.

lfabreges commented 6 years ago

v2.1.0 has just been published

spstratis commented 6 years ago

Thanks for the quick turn around, I just tested it out. New keys are now in the following format below for those who run into something similar in the future. This should work better moving forward with some minor tweaks on my server side code.

Pre-build en.json file "country":"Country"

Post-build en localizable.strings "_country_18aRgy" = "Country"