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

Add characters and words counts to editor #1478

Merged
merged 19 commits into from
Oct 10, 2022

Conversation

pedro-mendonca
Copy link
Member

@pedro-mendonca pedro-mendonca commented Aug 25, 2022

What?

Add Characters and Words counting to string editor

Fixes #1474

How?

Add counts below the string, on opening the editor row or when the input data changes, for every singular/plural textareas.

  • Add counts HTML on textarea focus to add counts on opening the editor row
  • Update counts HTML on textarea input change
  • All editor row textareas (singular and plurals) counts are updated on focus or input string change
  • Only the opened editor rows have the counts added/updated with JS, removing server process on page load.
  • The count uses WP core package Wordcount (suggested by @ocean90)
  • The Wordcount package ignores HTML tags and supports word counts for Asian languages to count every character as words
  • The words count now depends on each GP_Locale->word_count_type setting added in Add word count type to each Locale #1482

Screenshots or screencast

imagem

This JavaScript isn't prepared for i18n yet to avoid conflicts with previous PR #1369
Will be fixed after the PR merge.

This JavaScript is already prepared for i18n.

@pedro-mendonca pedro-mendonca marked this pull request as ready for review August 25, 2022 18:06
@pedro-mendonca pedro-mendonca requested a review from ocean90 August 25, 2022 18:08
pedro-mendonca and others added 7 commits September 5, 2022 13:27
Use 'input' instead of 'change keyup paste'

Co-authored-by: Dominik Schilling <[email protected]>
Use number_format_i18n()

Co-authored-by: Dominik Schilling <[email protected]>
Use number_format_i18n()

Co-authored-by: Dominik Schilling <[email protected]>
Supports the words type set in the installed language
@pedro-mendonca
Copy link
Member Author

pedro-mendonca commented Sep 6, 2022

@ocean90 The PR already uses the Gutenberg/core package Wordcount.

Also handles languages where word count is based on single characters, but reads the setting from the site language settings.

It would make much more sense to use a GP_Locale property to allow reading wordcounts based on the translation set instead of one single site setting for all GP_Locales.
Example: For an asian translation set, it should count characters as words, but german the word count should be based on letters separated by spaces. Currently, if the site locale is set to words, it will read the wordcount as words for all Locales.

Would it make sense to add it as a GP_Locale property instead?

@ocean90
Copy link
Member

ocean90 commented Sep 9, 2022

Also handles languages where word count is based on single characters, but reads the setting from the site language settings.

For the translation that definitely doesn't make sense so having this setting as part of GP_Locale sounds good to me. Maybe as a separate PR as done in #1479?

@pedro-mendonca
Copy link
Member Author

pedro-mendonca commented Sep 9, 2022

Maybe as a separate PR as done in #1479?

Yes, I'll wait for it to be merged. Will have to check wich alphabets use the words/characters for count.

@pedro-mendonca
Copy link
Member Author

pedro-mendonca commented Sep 9, 2022

@ocean90 do you mean we should add a property word_count_type to GP_Locale? Or we could just rely on the alphabet for it?

@amieiro
Copy link
Member

amieiro commented Sep 9, 2022

Maybe as a separate PR as done in #1479?

Yes, I'll wait for it to be merged. Will have to check wich alphabets use the words/characters for count.

Done @pedro-mendonca

@pedro-mendonca
Copy link
Member Author

pedro-mendonca commented Sep 9, 2022

Also done, added the property in #1482

@pedro-mendonca
Copy link
Member Author

@ocean90 the PR now reads the newly added GP_Locale word_count_type and every Locale editor behaves accordingly.
I think it's done.

@ocean90 ocean90 added this to the 4.0 milestone Oct 10, 2022
@ocean90 ocean90 enabled auto-merge (squash) October 10, 2022 19:18
@ocean90 ocean90 disabled auto-merge October 10, 2022 19:18
@ocean90 ocean90 merged commit 6eabbb8 into GlotPress:develop Oct 10, 2022
@pedro-mendonca pedro-mendonca deleted the characters-count branch October 11, 2022 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show the number of characters in translation
3 participants