PeterStaev / NativeScript-Drop-Down

A NativeScript DropDown widget.
Apache License 2.0
105 stars 65 forks source link

How to change "Done" text in iOS? #156

Closed erkanarslan closed 6 years ago

erkanarslan commented 6 years ago

I need to change that text for i18n. How can I provide a custom text, or use the device language?

PeterStaev commented 6 years ago

Hey @erkanarslan , since this is an iOS specific thing, there is no public API exposing this funvtionality. But you can use the drop down's private member _doneButton to access the native iOS `UIBarBottinItem' and set your text by using the native iOS api. So the code should look something like:

dropDown._doneButton.title = "Something";
TheOnlyMatt commented 6 years ago

this.dropDown.nativeElement._doneButton.title = "Suivant"; Not working for me

PeterStaev commented 6 years ago

@TheOnlyMatt this should be working, make sure you call this when you are sure you have the dropDown view child. Also not 100% sure that the nativeElement will be the drop down control itself.

TheOnlyMatt commented 6 years ago

I am not sure to have understood very well, should this code be in my project or in the plugin's code ?

PeterStaev commented 6 years ago

It should be in your project code.

TheOnlyMatt commented 6 years ago

This is my code :

if(isIOS){
            setTimeout(function(){
                self.dropDown.nativeElement._doneButton.title = "Suivant";
                declare const IQKeyboardManager: any;
                IQKeyboardManager.sharedManager().toolbarDoneBarButtonItemText = value;
                console.log("setting " + value + " as button")
            }, 5000)
        }

If I just set self.dropDown._doneButton.title = "Suivant"; an error is thrown : file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1466:24: ERROR TypeError: undefined is not an object (evaluating 'self.dropDown._doneButton.title = "Suivant"')

If I set the nativeElement, there is no error but the text is not changed :(

PeterStaev commented 6 years ago

I see you are using the IQKeyboardManager and I'm not sure how does it interact with the buttons that are added by the plugin. It could be overriding the toolbar and button I'm adding with the widget. Try to remove the IQKeyboardManager and see if that will resolve the problem.

PeterStaev commented 6 years ago

No further response so closing this one for now. In case you still have problems, please provide more details.

felixelgato92 commented 4 years ago

@PeterStaev I'm encountering this same issue: I tried setting it on the "loaded" event, since I figured it would be ready by then. I tried the following:

event.object._doneButton.title = "Something"

This fails silently but when running on the debugger, I get this:

Error processing "completions": TypeError: Cannot read property 'length' of undefined

Also title is originally null where I was expecting to see "Done" in here.

I'm using: "version": "4.0.1",

PeterStaev commented 4 years ago

@felixelgato92 , I just tried it and indeed it doesnt work. The plugin uses the localized built in Done bar button, so in this case you can't freely changed its label, but it is localized based on the iPhone language preferences. Sadly you will have to manually adjust the iOS code of the plugin if you want that label to be fully custom.

felixelgato92 commented 4 years ago

@PeterStaev I tried changing both the language preference on the phone (Simulator) and the region as well. I also tried changing the CFBundleDevelopmentRegion to fr, but no luck. Is there anything else I need to change?

PeterStaev commented 4 years ago

@felixelgato92 , sadly no idea as I havent done localized apps, so not how does Apple localize system buttons. The widget uses: https://developer.apple.com/documentation/uikit/uibarbuttonitem/systemitem/done And per Apples docs it is supposed to be localized.

Check if this: https://xamarin.github.io/bugzilla-archives/60/60308/bug.html#c6 wont resolve the problem.

felixelgato92 commented 4 years ago

I was looking into it a little bit more. It seems like Apple expects for "lproj" translation files to indicate what languages are supported. If the app doesn't have those files then iOS won't translate those buttons which makes sense for consistency sake. Meaning if someone has French as the selected language, but your app doesn't support it, you don't want the app to just be translated at some random places.

sc85 commented 4 years ago

You might be able to change the language of the button by editing the Info.plist file (see app/App_Resource/iOS/Info.plist). As @felixelgato92 mentioned changing CFBundleDevelopmentRegion does not seem to be sufficient. Instead you also need to add CFBundleLocalizations followed by an array of the supported languages. In my case (German) the beginning of the file now looks like this:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>de</string>
    <key>CFBundleLocalizations</key>
    <array>
        <string>de</string>
    </array>
        ...

Good luck and stay healthy!