kelvinhokk / cordova-plugin-localization-strings

Cordova Plugin for Localization of Strings on the App
MIT License
119 stars 106 forks source link

Plugin not working on Release Build iOS #49

Closed paknecht closed 4 years ago

paknecht commented 5 years ago

Hi I want to do some localization for the CocoaKey: NSCameraUsageDescription. Unfortunately, the plugin doesn't work when I make a Cordova Release Build. What I use: Cordova cli: 8.1.2 XCode: 10.2.1 Deployment Target: 10.1

When I build my app with the command: cordova build Everything works fine and when I open the xCode Workspace I see the Localizable.strings and the *.lproj Files are at the right place

But when I build my app like this: cordova build ios --device --release --buildConfig="/path/to/xcodebuild.json" the localization is not working. The *.lproj Files are at the right place but when I open the xCode I don't see the Localizable.strings

my files look like this (example en.json): { "config_ios" : { "NSCameraUsageDescription": "The application needs access to your camera so you can scan invoices and deliver them digitally to Simplex." } }

Thanks for your help.

rodrigograca31 commented 5 years ago

I can't help you much since I know nearly 0 about iOS but you say the file is in the right location..... and isnt the --device flag to run on the device? (at least it is for Android)

if you do cordova run ios --device (or without --device) does it work? (to check if its an issue related to the release build process...)

gwynjudd commented 5 years ago

I'm trying to track down a similar issue. I've got it narrowed down to the following circumstance, and I wonder if you are seeing the same thing.

Basically, what I'm seeing is that "sometimes" (haven't worked out the exact situation) a build will work correctly and the generated xcode project will contain the expected localizations:

image

But "other times", the build will not work correctly, and the generated xcode project will not contain the expected localizations:

image

The two screenshots are taken from builds that were run at different times on our build server. They are from different branches, but there aren't any relevant changes to localizations or that kind of thing that I can identify. I have seen the same situation occur for me on my own development environment from time to time, but hadn't really had the opportunity to dig into it. Please treat this as evidence that "something weird" is going on.

Here is some excerpts from the build logs for the above two builds, that I think are relevant.

First, from the one that "worked correctly":


Updating ios **** to use workspace.

> stayinfront.touch@1.0.0 add-strings /Users/****/jenkins-slave/workspace/Touch_iOS_Shell_releases_iOS_6.1
> npx cordova plugin add https://github.com/gwynjudd/cordova-plugin-localization-strings#utf --fetch --nosave

Installing "cordova-plugin-localization-strings" for ios

> stayinfront.touch@1.0.0 prepare:ios1 /Users/****/jenkins-slave/workspace/Touch_iOS_Shell_releases_iOS_6.1
> npx cordova prepare ios

...

====== Assets moved from ./scripts/ios/AppDelegate.m to ./platforms/ios/StayinFront Touch/Classes/AppDelegate.m ======
====== Assets moved from ./scripts/ios/AppDelegate.h to ./platforms/ios/StayinFront Touch/Classes/AppDelegate.h ======
====== Assets moved from ./scripts/ios/exportOptions.plist to ./platforms/ios/exportOptions.plist ======
====== Assets moved from ./scripts/ios/adhocOptions.plist to ./platforms/ios/adhocOptions.plist ======
====== Assets moved from ./scripts/ios/phonegap.js to ./platforms/ios/www/phonegap.js ======
new pbx project written with localization groups
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Customize app title)
[Pipeline] withEnv

Note the key string above "new pbx project written with localization groups". This string is found here (https://github.com/kelvinhokk/cordova-plugin-localization-strings/blob/c4285d7ba1513e1a425795bd1aea687e738f2e76/scripts/create_ios_strings.js#L151).

Now follows similar excerpt from the build that didn't work correctly:

Updating ios **** to use workspace.

> stayinfront.touch@1.0.0 add-strings /Users/****/jenkins-slave/workspace/Touch iOS Shell 6.0/iOS
> npx cordova plugin add https://github.com/gwynjudd/cordova-plugin-localization-strings#utf --fetch --nosave

Plugin "cordova-plugin-dialogs" already installed on ios.

> stayinfront.touch@1.0.0 prepare:ios1 /Users/****/jenkins-slave/workspace/Touch iOS Shell 6.0/iOS
> npx cordova prepare ios

...

====== Assets moved from ./scripts/ios/AppDelegate.m to ./platforms/ios/StayinFront Touch/Classes/AppDelegate.m ======
====== Assets moved from ./scripts/ios/AppDelegate.h to ./platforms/ios/StayinFront Touch/Classes/AppDelegate.h ======
====== Assets moved from ./scripts/ios/exportOptions.plist to ./platforms/ios/exportOptions.plist ======
====== Assets moved from ./scripts/ios/adhocOptions.plist to ./platforms/ios/adhocOptions.plist ======
====== Assets moved from ./scripts/ios/phonegap.js to ./platforms/ios/www/phonegap.js ======
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Customize app title)
[Pipeline] withEnv

Note that the key string doesn't appear. Without this code running (https://github.com/kelvinhokk/cordova-plugin-localization-strings/blob/c4285d7ba1513e1a425795bd1aea687e738f2e76/scripts/create_ios_strings.js#L151), the project doesn't get updated.

gwynjudd commented 5 years ago

More detail, here is a screenshot showing the generated project and resources folder with localizable strings as expected in the build that worked correctly:

image

Versus, in the build that did not work, the resources folder does not contain the localized string files:

image

gwynjudd commented 5 years ago

More detail on this. I found that for the build that worked OK, I am getting this message at the point of installing the plugin:

Updating ios **** to use workspace.

> stayinfront.touch@1.0.0 add-strings /Users/****/jenkins-slave/workspace/Touch_iOS_Shell_releases_iOS_6.1
> npx cordova plugin add https://github.com/gwynjudd/cordova-plugin-localization-strings#utf --fetch --nosave

Installing "cordova-plugin-localization-strings" for ios

> stayinfront.touch@1.0.0 prepare:ios1 /Users/****/jenkins-slave/workspace/Touch_iOS_Shell_releases_iOS_6.1
> npx cordova prepare ios

Key point being this message Installing "cordova-plugin-localization-strings" for ios.

For the build that fails, I get a different message:

Updating ios **** to use workspace.

> stayinfront.touch@1.0.0 add-strings /Users/****/jenkins-slave/workspace/Touch iOS Shell 6.0/iOS
> npx cordova plugin add https://github.com/gwynjudd/cordova-plugin-localization-strings#utf --fetch --nosave

Plugin "cordova-plugin-dialogs" already installed on ios.

> stayinfront.touch@1.0.0 prepare:ios1 /Users/****/jenkins-slave/workspace/Touch iOS Shell 6.0/iOS
> npx cordova prepare ios

Note the message is different Plugin "cordova-plugin-dialogs" already installed on ios..

rodrigograca31 commented 5 years ago

:thinking: the plugin uses after_prepare but it should work according to the docs https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/

why is it installing it? does your build thing always installs everything from scratch? instead of just running the project?

also, in latest versions of cordova they started saving plugins in package.json and config.xml, try to remove the plugin completely from the project and from both files (you might have to do it manually) and then reinstall again........ https://cordova.apache.org/news/2017/05/04/cordova-7.html

Good luck, I can't help much more as Im not familiar with iOS

gwynjudd commented 5 years ago

The build is running in jenkins so it has to do at least a cordova prepare before being able to build. Doing cordova plugin add for this plugin seems to help with getting it to work correctly.

If I still see the issue, I'll try to change the build so that it doesn't add the plugin each time and see if that helps or hinders. But for now I've managed to do some stuff to work around it.

rodrigograca31 commented 4 years ago

@gwynjudd is this still an issue?

gwynjudd commented 4 years ago

@rodrigograca31 not for me. I had put in some work-arounds a while ago that seems to have helped. From my side it is probably ok to close this issue - if I get time (hah) I may remove the work-arounds and see if it reappears.

rodrigograca31 commented 4 years ago

:+1: