Kelderic / featured-galleries

Do you like giving posts a Featured Image? Try out a Featured Gallery. It's like a Featured Images ... except as many images as you want.
GNU General Public License v3.0
3 stars 1 forks source link

Internationalize JS file #3

Open mrleemon opened 5 years ago

mrleemon commented 5 years ago

In order to internationalize the buttons and titles found in the fg-admin.js file, you need to pass the localized strings from PHP via data- attributes. This is the way WooCommerce does it in its gallery metabox. For example:

controller.php

... <button type="button" class="button hide-if-no-js" id="fg_select" data-create="' . __( 'Arrange Images', 'featured-gallery' ) . '" data-update="' . __( 'Set Featured Gallery', 'featured-gallery' ) . '" data-insert="' . __( 'Set Featured Gallery', 'featured-gallery' ) . '">' . $selectButtonText . '</button> ...

fg-admin.js

self.el.buttonSelect.addEventListener('click', function(event){
    var $el = $( this );

    // CUSTOMIZE THE MAIN BUTTON TEXT
    wp.media.view.l10n.createNewGallery = $el.data('create');  // string from the data-create attr
    wp.media.view.l10n.updateGallery = $el.data('update');  // string from the data-update attr
    wp.media.view.l10n.insertGallery = $el.data('insert');  // string from the data-insert attr

    // OPEN THE MODAL
    self.frame.open();
});
Kelderic commented 5 years ago

Hi @mrleemon, thanks for the input! I'll take a look at this when I have a bit of time. It'll probably be next weekend, though, before I have a chance to really dive in, because it's been a LONG time since I did anything with internationalization.