| 1 |
import { __, sprintf } from '@wordpress/i18n'; |
| 2 |
|
| 3 |
// Block types whose primary edited value is human-readable, translatable text. |
| 4 |
// On a non-default-language render Quick Edit writes the source post_content |
| 5 |
// while the screen shows the translation, so these are blocked and a notice is |
| 6 |
// shown instead. Image, color, alignment, price, and link edits touch shared |
| 7 |
// (untranslated) source and stay available — deliberately absent here. |
| 8 |
const TEXT_BEARING_BLOCK_TYPES = new Set([ |
| 9 |
'core/paragraph', |
| 10 |
'core/heading', |
| 11 |
'core/button', |
| 12 |
'core/site-title', |
| 13 |
'core/site-tagline', |
| 14 |
'core/navigation-link', |
| 15 |
'core/navigation-submenu', |
| 16 |
'product:name', |
| 17 |
'product:short_description', |
| 18 |
'product:description', |
| 19 |
]); |
| 20 |
|
| 21 |
export const isTextBearing = (blockType) => |
| 22 |
TEXT_BEARING_BLOCK_TYPES.has(blockType); |
| 23 |
|
| 24 |
const PLUGIN_LABELS = { |
| 25 |
translatepress: 'TranslatePress', |
| 26 |
wpml: 'WPML', |
| 27 |
polylang: 'Polylang', |
| 28 |
}; |
| 29 |
|
| 30 |
export const translatedNoticeMessage = (plugin) => { |
| 31 |
const label = PLUGIN_LABELS[plugin]; |
| 32 |
if (!label) { |
| 33 |
return __( |
| 34 |
"Quick Edit can't edit translated content on this page.", |
| 35 |
'extendify-local', |
| 36 |
); |
| 37 |
} |
| 38 |
return sprintf( |
| 39 |
// translators: %s is the multilingual plugin name, e.g. "TranslatePress". |
| 40 |
__( |
| 41 |
"Quick Edit can't edit translated content — manage translations in %s.", |
| 42 |
'extendify-local', |
| 43 |
), |
| 44 |
label, |
| 45 |
); |
| 46 |
}; |
| 47 |
|
| 48 |
// Detected server-side at page render (Frontend::enqueue, where the request |
| 49 |
// language is known) and shipped on the inline-script global. The REST save |
| 50 |
// request isn't language-scoped, so the save guard reads the value the client |
| 51 |
// forwards rather than re-detecting. Shape: |
| 52 |
// { isTranslated: boolean, plugin: 'translatepress'|'wpml'|'polylang'|null }. |
| 53 |
export const getTranslatedContext = () => |
| 54 |
window.extQuickEditData?.translatedContext ?? null; |
| 55 |
|
| 56 |
export const isTranslatedRender = () => !!getTranslatedContext()?.isTranslated; |
| 57 |
|