Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localizing hardcoded messages #339

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<clobbers target="CameraPopoverHandle" />
</js-module>

<resource-file src="src/ios/Camera.strings" target="en.lproj/Camera.strings" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know anything about iOS. What does target="en.lproj/Camera.strings" mean here?

Copy link
Author

@kohlia kohlia Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will copy the hardcoded message file Camera.strings into a language location en.lproj as Camera.strings and we can load the message from this file in the code at runtime

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so en.lproj is a magic thing that the project will know about and load en.lproj/Camera.strings without any additional configuration?

Should the file maybe be called cordova-plugin-camera.strings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The en.lproj or fr.lproj or ar.lproj etc are understood by app to load corresponding language files
You are free to name the strings file just update the plugin.xml accordingly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was really more a question - to make sure developers know what the file is from and for. You created the PR, so you can decide and adapt or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it like this then I have no issues

<header-file src="src/ios/UIImage+CropScaleOrientation.h" />
<source-file src="src/ios/UIImage+CropScaleOrientation.m" />
<header-file src="src/ios/CDVCamera.h" />
Expand Down
6 changes: 3 additions & 3 deletions src/ios/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
NSString* settingsButton = (&UIApplicationOpenSettingsURLString != NULL)
? NSLocalizedString(@"Settings", nil)
? NSLocalizedStringFromTable(@"camera.settings", @"Camera", nil)
: nil;
#pragma clang diagnostic pop

// Denied; show an alert
dispatch_async(dispatch_get_main_queue(), ^{
[[[UIAlertView alloc] initWithTitle:[[NSBundle mainBundle]
objectForInfoDictionaryKey:@"CFBundleDisplayName"]
message:NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.", nil)
message:NSLocalizedStringFromTable(@"camera.prohibited", @"Camera", nil)
delegate:weakSelf
cancelButtonTitle:NSLocalizedString(@"OK", nil)
cancelButtonTitle:NSLocalizedStringFromTable(@"camera.ok", @"Camera", nil)
otherButtonTitles:settingsButton, nil] show];
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/ios/Camera.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"camera.prohibited" = "Access to the camera has been prohibited; please enable it in the Settings app to continue.";
"camera.ok" = "OK";
"camera.settings" = "Settings";