Uploaded image for project: 'Planet4'
  1. Planet4
  2. PLANET-6262

FrontendRichText in Cookies block causes unnecessary dependency on wp-i18n scripts

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Should have Should have
    • None
    • None

      We need to load wp-i18n in the front end partially because the FrontendRichText component includes labels that are only used in the editor. These need to be translated, and this happens in the block's attributes. The block then internally doesn't use these on the front end.

      wp-i18n in turn depends on wp-polyfill, which we otherwise wouldn't need to load.

      There's also this code in master piece that depends on wp-i18n, but it seems easy to avoid. It's 2 calls, the second actually does a loop for each country group letter and creates a separate label. We can check if people actually translate these for each letter. Both translations are only used in the aria-label.

      https://github.com/greenpeace/planet4-master-theme/blob/a872eb5a98dd58e45da522be48704805ebc845ac/assets/src/js/country_select.js#L30-L30 

      https://github.com/greenpeace/planet4-master-theme/blob/a872eb5a98dd58e45da522be48704805ebc845ac/assets/src/js/country_select.js#L47-L47 

      If we separate out the admin area code, similar to how it happens in other components, we would not have to load wp-i18n and wp-polyfill anymore.

      Perhaps a quicker fix would be to catch __ if it's not defined and assign a noop function to it.

      const __ = wp.i18n?.__ || s => s; 

            Unassigned Unassigned
            pvincent Pieter Vincent (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: