Skip to content

Store DeepL locale in PLL_Language object#1794

Open
Chouby wants to merge 4 commits into
masterfrom
additional-locales
Open

Store DeepL locale in PLL_Language object#1794
Chouby wants to merge 4 commits into
masterfrom
additional-locales

Conversation

@Chouby
Copy link
Copy Markdown
Contributor

@Chouby Chouby commented Jan 12, 2026

Two goals for this PR

  1. introduce a new PLL_Language property for the DeepL locale.
    -> to match the other W3C and Facebook locales.
    -> to allow to simplify Deepl::get_target_code().
  2. introduce a new filter pll_additional_locales to allow developers to add W3C, Facebook or DeepL locales which would not be already included in our predefined list. Only these properties are accepted in this filter.

Bonus: PLL_Language_Factory PHPStan errors are fixed.

@Chouby Chouby added this to the 3.8 milestone Jan 12, 2026
@Chouby Chouby self-assigned this Jan 12, 2026
Frédéric Demarle added 2 commits January 12, 2026 22:53
@Screenfeed Screenfeed self-requested a review January 21, 2026 12:36
Copy link
Copy Markdown
Contributor

@Screenfeed Screenfeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some points we have to discuss.

Also:
After Facebook and DeepL, we're adding another class property for a 3rd party locale. Then maybe we will have to add another one for the next machine translation service we'll add. And maybe another one someday...

So, here's is an idea:
Instead of adding another property, we could treat these locales differently, a bit like PLL_Language::$term_props.
Technically:

  1. We keep $w3c as a class property (like we did for $term_id).
  2. We deprecate the property $facebook (like we did with $term_taxonomy_id and others).
  3. We create a new private property $service_locales = array() that will contain $w3c, $facebook, and $deepl.
  4. We create a new public method PLL_Language::get_service_locale( string $service ): ?string.
  5. The method Languages::to_array() will need an adjustment.
  6. We use this method in Jetpack and WPSeo integrations.

What do you think?

Comment on lines +97 to +98
if ( ! is_array( $description ) || empty( $description['locale'] ) || ! is_string( $description['locale'] ) ) {
return null;
Copy link
Copy Markdown
Contributor

@Screenfeed Screenfeed Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the current behavior. Previously we were still returning a WP_Language object in case of broken language, while now we return null. Is this something that we want?

Comment thread src/language-factory.php
Comment on lines -172 to -185
$data['is_rtl'] = ! empty( $data['is_rtl'] ) ? 1 : 0;

$positive_fields = array( 'term_group', 'page_on_front', 'page_for_posts' );

foreach ( $positive_fields as $field ) {
$data[ $field ] = ! empty( $data[ $field ] ) ? absint( $data[ $field ] ) : 0;
}

$data['active'] = isset( $data['active'] ) ? (bool) $data['active'] : true;

if ( array_key_exists( 'fallbacks', $data ) && ! is_array( $data['fallbacks'] ) ) {
unset( $data['fallbacks'] );
}

Copy link
Copy Markdown
Contributor

@Screenfeed Screenfeed Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't remove these, this method is used by PLL_Language_Factory::get(), which is used by PLL_Languages::get_list() to build the PLL_Language object, based on the transient value.

If the language term's description needs some sanitization (which is done earlier now), then the transient's value too IMHO.

* @return string[]
*/
private function get_languages() {
private function get_additional_locales( $locale ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are safe here.

Suggested change
private function get_additional_locales( $locale ) {
private function get_additional_locales( string $locale ): array {

@Chouby Chouby removed this from the 3.8 milestone Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants