Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#45320 closed enhancement (duplicate)

Allow preloading the translations in `load_script_textdomain`

Reported by: strategio's profile strategio Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0
Component: I18N Keywords: needs-patch
Focuses: Cc:

Description

Problem:

Now that we can translate strings on the JS side and with the introduction of wp_set_script_translations, we have no way to override the translations coming from the JSON files.

We need a filter allowing to delegate the process of loading the translations.

Suggestion:

Ideally, we could have a filter inside load_script_textdomain where we could provide our own set of translations (as a JED object).

Here's an idea:

<?php

function load_script_textdomain( $handle, $domain, $path = null ) {
        global $wp_scripts;

        $json_translations = apply_filters( 'pre_load_script_textdomain', false, $handle, $domain, $path );

        if ( $json_translations ) {
                return $json_translations;
        }

        //...
}

Why we need it:

In WPML, we store the string translations in the DB and we offer the user the ability to add/edit translations. Apart overwriting the JSON files (which could be an option, but would also introduce other issues), we have no way to provide our own translations to the JS script.

Attachments (1)

patch_4532.patch (803 bytes) - added by strategio 6 years ago.
Patch to introduce the filter pre_load_script_textdomain

Download all attachments as: .zip

Change History (4)

#1 @ocean90
6 years ago

  • Keywords needs-patch added
  • Severity changed from critical to normal
  • Type changed from feature request to enhancement

@strategio
6 years ago

Patch to introduce the filter pre_load_script_textdomain

#2 @strategio
6 years ago

Hi @ocean90,

I suggested a patch to introduce the filter pre_load_script_textdomain. As explained, we have no way to filter these translations and this is blocking for us. Could you please raise the priority for this ticket.

Thanks!

#3 @swissspidy
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #45425.

Marking as duplicate because the other ticket has a more complete patch and is already slated for a milestone.

Note: See TracTickets for help on using tickets.