TypeRocket / core

TypeRocket core source files where all the magic lives.
https://typerocket.com
36 stars 21 forks source link

Cannot localize title and button in media overlay #38

Closed nebulousGirl closed 5 years ago

nebulousGirl commented 5 years ago

https://github.com/TypeRocket/core/blob/cd8dfac86491c2ae4cf12645eb828e080970a777/assets/js/tooling/media.js#L37

The labels used in the media overlay are hardcoded in the JavaScript. It would be useful to provide a data attribute so that it can be localized.

nebulousGirl commented 5 years ago

There is a workaround by defining another click event and preventing further propagation:

  var set_croppie_uploader = function(button, field) {
    var btnTitle, temp_frame, title, typeInput;
    title = 'Select an Image';
    btnTitle = 'Use Image';
    typeInput = 'image';
    temp_frame = wp.media({
        title: title,
        button: {
            text: btnTitle
        },
        library: {
            type: typeInput
        },
        multiple: false
    });
    temp_frame.uploader.options.uploader.params.allowed_mime_types = 'image';
    temp_frame.on('select', function() {
        var attachment, url;
        attachment = temp_frame.state().get('selection').first().toJSON();
        url = attachment.sizes.full.url;
        $(field).val(attachment.id);
        $(button).parent().next().html('<img src="' + url + '"/>');
    });
    wp.media.frames.image_frame = temp_frame;
    wp.media.frames.image_frame.open();
    return false;
};

$('.myWrapper').on('click', '.image-picker-button', function (e) {
          e.stopPropagation();
          var field;
          field = $(this).parent().prev();
          set_croppie_uploader($(this), field[0]);
        });
kevindees commented 5 years ago

@nebulousGirl

This has now been done through js. The fix is on the master branch for core now.

https://github.com/TypeRocket/core/commit/2c02801869f83de317372384014235f22c2d2fba https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/