PluginProbe
Extendify / 3.1.2
Extendify v3.1.2
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / QuickEdit / lib / translated.js

translated.js in Extendify 3.1.2, at src/QuickEdit/lib/translated.js

57 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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