From c8348ee8d675e9c8059e89f25071e5cf62a8155b Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Tue, 19 May 2026 14:19:11 +0530 Subject: [PATCH 1/3] Use user's local to identify content classification suggestion limit to use words or characters --- .../components/SuggestionPanel.tsx | 14 +++++++---- .../components/useContentClassification.ts | 23 +++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/experiments/content-classification/components/SuggestionPanel.tsx b/src/experiments/content-classification/components/SuggestionPanel.tsx index a70c90194..f941c88d9 100644 --- a/src/experiments/content-classification/components/SuggestionPanel.tsx +++ b/src/experiments/content-classification/components/SuggestionPanel.tsx @@ -42,6 +42,7 @@ export default function SuggestionPanel( { handleAccept, handleDismiss, handleDismissAll, + wordCountType, } = useContentClassification( taxonomy ); const taxonomyObject: any = select( coreStore ).getTaxonomy( taxonomy ); @@ -73,10 +74,15 @@ export default function SuggestionPanel( { { ! hasEnoughContent && ! hasSuggestions && (

- { __( - 'Add more content to enable AI suggestions (approximately 150 words).', - 'ai' - ) } + { wordCountType === 'words' + ? __( + 'Add more content to enable AI suggestions (approximately 150 words).', + 'ai' + ) + : __( + 'Add more content to enable AI suggestions (approximately 150 characters).', + 'ai' + ) }

) } diff --git a/src/experiments/content-classification/components/useContentClassification.ts b/src/experiments/content-classification/components/useContentClassification.ts index f3ba49d5e..f88fddd2e 100644 --- a/src/experiments/content-classification/components/useContentClassification.ts +++ b/src/experiments/content-classification/components/useContentClassification.ts @@ -5,12 +5,13 @@ /** * WordPress dependencies */ +import { _x } from '@wordpress/i18n'; import { dispatch, select } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { store as editorStore } from '@wordpress/editor'; import { useState, useCallback } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; -import { count as wordCount } from '@wordpress/wordcount'; +import { count as wordCount, type Strategy } from '@wordpress/wordcount'; import { addQueryArgs } from '@wordpress/url'; import apiFetch from '@wordpress/api-fetch'; @@ -26,7 +27,7 @@ import type { ContentClassificationData, } from '../types'; -const MINIMUM_WORD_COUNT = 150; +const MINIMUM_WORD_CHARACTER_COUNT = 150; const NOTICE_ID = 'ai_content_classification_error'; const getSettings = (): ContentClassificationData => @@ -117,6 +118,7 @@ export function useContentClassification( taxonomy: string ): { handleAccept: ( suggestion: TagSuggestion ) => void; handleDismiss: ( suggestion: TagSuggestion ) => void; handleDismissAll: () => void; + wordCountType: Strategy; } { const postId = select( editorStore ).getCurrentPostId() as number; const content = select( editorStore ).getEditedPostContent(); @@ -124,9 +126,21 @@ export function useContentClassification( taxonomy: string ): { const [ suggestions, setSuggestions ] = useState< TagSuggestion[] >( [] ); const { removeNotice, createErrorNotice } = dispatch( noticesStore ) as any; - // Check if content has enough words. + /** + * 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. + */ + const wordCountType = _x( + 'words', + 'Word count type. Do not translate!', + 'ai' + ) as Strategy; + + // Check if content has enough words or characters. const hasEnoughContent = - wordCount( content || '', 'words' ) >= MINIMUM_WORD_COUNT; + wordCount( content || '', wordCountType ) >= + MINIMUM_WORD_CHARACTER_COUNT; const handleGenerate = useCallback( async () => { if ( ! ensureProvider( NOTICE_ID ) ) { @@ -203,6 +217,7 @@ export function useContentClassification( taxonomy: string ): { handleAccept, handleDismiss, handleDismissAll, + wordCountType, }; } From baa1e4a0d4959404de64dce273aff19c6fa0c1c8 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Tue, 19 May 2026 14:33:55 +0530 Subject: [PATCH 2/3] Remove text domain and used default text domain --- .../components/useContentClassification.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/experiments/content-classification/components/useContentClassification.ts b/src/experiments/content-classification/components/useContentClassification.ts index f88fddd2e..49c98e400 100644 --- a/src/experiments/content-classification/components/useContentClassification.ts +++ b/src/experiments/content-classification/components/useContentClassification.ts @@ -131,10 +131,10 @@ export function useContentClassification( taxonomy: string ): { * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. * Do not translate into your own language. */ + // eslint-disable-next-line @wordpress/i18n-text-domain const wordCountType = _x( 'words', - 'Word count type. Do not translate!', - 'ai' + 'Word count type. Do not translate!' ) as Strategy; // Check if content has enough words or characters. From e0c4bb41034c64677d275db6634afc5b98a7b2dc Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Tue, 19 May 2026 15:00:17 +0530 Subject: [PATCH 3/3] Add comment on why to use default text domain --- .../components/useContentClassification.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/experiments/content-classification/components/useContentClassification.ts b/src/experiments/content-classification/components/useContentClassification.ts index 49c98e400..acc1d7116 100644 --- a/src/experiments/content-classification/components/useContentClassification.ts +++ b/src/experiments/content-classification/components/useContentClassification.ts @@ -130,6 +130,11 @@ export function useContentClassification( taxonomy: string ): { * 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. + * + * Uses the default (core) text domain so the word count type stays consistent + * with WordPress core's behavior. + * + * See - https://github.com/WordPress/ai/pull/577#discussion_r3265155502 */ // eslint-disable-next-line @wordpress/i18n-text-domain const wordCountType = _x(