Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research better solution for detecting languages with different word count #403

Open
Zodiac1978 opened this issue Jul 1, 2021 · 8 comments

Comments

@Zodiac1978
Copy link
Member

We are using a core string to detect languages with different word counts (like asian langauges) in:

antispam-bee/antispam_bee.php

Lines 1860 to 1873 in b21d41f

/*
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
* Do not translate into your own language.
*/
if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
preg_match_all( '/./u', $text, $words_array );
if ( isset( $words_array[0] ) ) {
$word_count = count( $words_array[0] );
}
} else {
$words_array = preg_split( "/[\n\r\t ]+/", $text, -1, PREG_SPLIT_NO_EMPTY );
$word_count = count( $words_array );
}

There are at least two problems with this approach:

  • If the core string changes we do need to change this test accordingly. If we do not have any tests for this to check it automatically, this will easily slip through.
  • The string also will be parsed by the PO-Parser from WordPress.org and is therefore on translate.wordpress.org. I think this will be not used, but I do not found a way to disable parsing it.

Additionally there is problem with the translator comment which is not shown:
https://translate.wordpress.org/projects/wp-plugins/antispam-bee/stable/de/default/?filters%5Bstatus%5D=either&filters%5Boriginal_id%5D=7264244&filters%5Btranslation_id%5D=61317391

@Zodiac1978
Copy link
Member Author

Maybe @swissspidy can help us here? Or @ocean90?

@swissspidy
Copy link
Contributor

  • If the core string changes we do need to change this test accordingly. If we do not have any tests for this to check it automatically, this will easily slip through.

I'd just add the antispam-bee text domain.

  • The string also will be parsed by the PO-Parser from WordPress.org and is therefore on translate.wordpress.org. I think this will be not used, but I do not found a way to disable parsing it.

This can't be disabled.

Additionally there is problem with the translator comment which is not shown:
translate.wordpress.org/projects/wp-plugins/antispam-bee/stable/de/default/?filters%5Bstatus%5D=either&filters%5Boriginal_id%5D=7264244&filters%5Btranslation_id%5D=61317391

I see the comment:

Screenshot 2021-07-29 at 14 05 54

@Zodiac1978
Copy link
Member Author

Zodiac1978 commented Jul 29, 2021

I'd just add the antispam-bee text domain.

This is not handled by the locale options? It looks like a lot redundant work if this needs to be added to every plugin which needs it. The locale is saving the starting day of the week, why not something like this? Couldn't we add this to the locale?

This can't be disabled.

We could use the underlying internal translation function, but I think this is not recommended too.

I see the comment:

Thanks for checking. Maybe I just overseen it, because it was collapsed ...

@swissspidy
Copy link
Contributor

The locale is saving the starting day of the week, why not something like this? Couldn't we add this to the locale?

Yeah why not.

Found https://core.trac.wordpress.org/ticket/39733 and https://core.trac.wordpress.org/ticket/47511 that look related.

@Zodiac1978
Copy link
Member Author

I've added my comment to the trac ticket https://core.trac.wordpress.org/ticket/47511#comment:19

Summary: This solution is used on 65 plugins at the moment and it is used inconsistently. WooCommerce is using its own translation, but Jetpack is using the core translation. Although this string is added to GlotPress and remains unused. Solution could be to add this information to the WP_Locale object which could be easily used in this case.

@Zodiac1978
Copy link
Member Author

There is no traction on the ticket and no action item for this issue, so I close this, as we cannot do anything here.

If someone has a strong opinion on adding the ASB text domain, please re-open this issue.

@pedro-mendonca
Copy link
Contributor

@Zodiac1978 I hope this is a solution :)

https://core.trac.wordpress.org/ticket/56698

@Zodiac1978
Copy link
Member Author

The ticket got accepted and comes with WP 6.2, so we could use the new way to get the info. Re-opening.

@Zodiac1978 Zodiac1978 reopened this Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants