Skip to content

Commit 0c09fc8

Browse files
authored
feat(camera): make prompt strings localizable (#2631)
1 parent 89c64af commit 0c09fc8

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ private void doShow(PluginCall call) {
104104

105105
private void showPrompt(final PluginCall call) {
106106
// We have all necessary permissions, open the camera
107+
String promptLabelPhoto = call.getString("promptLabelPhoto", "From Photos");
108+
String promptLabelPicture = call.getString("promptLabelPicture", "Take Picture");
109+
107110
JSObject fromPhotos = new JSObject();
108-
fromPhotos.put("title", "From Photos");
111+
fromPhotos.put("title", promptLabelPhoto);
109112
JSObject takePicture = new JSObject();
110-
takePicture.put("title", "Take Picture");
113+
takePicture.put("title", promptLabelPicture);
111114
Object[] options = new Object[] {
112115
fromPhotos,
113116
takePicture

core/src/core-plugin-definitions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,19 @@ export interface CameraOptions {
343343
* iOS only: The presentation style of the Camera. Defaults to fullscreen.
344344
*/
345345
presentationStyle?: 'fullscreen' | 'popover';
346+
347+
/**
348+
* If use CameraSource.Prompt only, can change Prompt label.
349+
* default:
350+
* promptLabelHeader : 'Photo' // iOS only
351+
* promptLabelCancel : 'Cancel' // iOS only
352+
* promptLabelPhoto : 'From Photos'
353+
* promptLabelPicture : 'Take Picture'
354+
*/
355+
promptLabelHeader?: string;
356+
promptLabelCancel?: string;
357+
promptLabelPhoto?: string;
358+
promptLabelPicture?: string;
346359
}
347360

348361
export enum CameraSource {

ios/Capacitor/Capacitor/Plugins/Camera.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,21 @@ public class CAPCameraPlugin : CAPPlugin, UIImagePickerControllerDelegate, UINav
101101

102102
func showPrompt(_ call: CAPPluginCall) {
103103
// Build the action sheet
104-
let alert = UIAlertController(title: "Photo", message: nil, preferredStyle: UIAlertController.Style.actionSheet)
105-
alert.addAction(UIAlertAction(title: "From Photos", style: .default, handler: { (action: UIAlertAction) in
104+
let promptLabelHeader = call.getString("promptLabelHeader") ?? "Photo"
105+
let promptLabelPhoto = call.getString("promptLabelPhoto") ?? "From Photos"
106+
let promptLabelPicture = call.getString("promptLabelPicture") ?? "Take Picture"
107+
let promptLabelCancel = call.getString("promptLabelCancel") ?? "Cancel"
108+
109+
let alert = UIAlertController(title: promptLabelHeader, message: nil, preferredStyle: UIAlertController.Style.actionSheet)
110+
alert.addAction(UIAlertAction(title: promptLabelPhoto, style: .default, handler: { (action: UIAlertAction) in
106111
self.showPhotos(call)
107112
}))
108113

109-
alert.addAction(UIAlertAction(title: "Take Picture", style: .default, handler: { (action: UIAlertAction) in
114+
alert.addAction(UIAlertAction(title: promptLabelPicture, style: .default, handler: { (action: UIAlertAction) in
110115
self.showCamera(call)
111116
}))
112117

113-
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction) in
118+
alert.addAction(UIAlertAction(title: promptLabelCancel, style: .cancel, handler: { (action: UIAlertAction) in
114119
self.call?.error("User cancelled photos app")
115120
}))
116121

0 commit comments

Comments
 (0)