Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
wp-content
/
plugins
/
preferred-languages
/
build
/
Filename :
preferred-languages.js
back
Copy
(()=>{"use strict";var e={n:a=>{var r=a&&a.__esModule?()=>a.default:()=>a;return e.d(r,{a:r}),r},d:(a,r)=>{for(var n in r)e.o(r,n)&&!e.o(a,n)&&Object.defineProperty(a,n,{enumerable:!0,get:r[n]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a)};const a=window.wp.element,r=window.wp.domReady;var n=e.n(r);const l=window.wp.data,t=window.wp.i18n,s=window.wp.components,o=window.wp.keyboardShortcuts,i=window.wp.a11y;function c(e,a,r){const n=e.splice(a,1)[0];return e.splice(r,0,n),e}const g=window.ReactJSXRuntime;function d({languages:e,selectedLanguage:a,onMoveUp:r,onMoveDown:n,onRemove:l}){const i=!a||e[0]?.locale===a?.locale,c=!a||e[e.length-1]?.locale===a?.locale,d=!a;return(0,o.useShortcut)("preferred-languages/move-up",(e=>{e.preventDefault(),i||r()})),(0,o.useShortcut)("preferred-languages/move-down",(e=>{e.preventDefault(),c||n()})),(0,o.useShortcut)("preferred-languages/remove",(e=>{e.preventDefault(),d||l()})),(0,g.jsx)("div",{className:"active-locales-controls",children:(0,g.jsxs)("ul",{children:[(0,g.jsx)("li",{children:(0,g.jsx)(s.Button,{variant:"secondary",showTooltip:!0,"aria-keyshortcuts":"Alt+ArrowUp","aria-label":(0,t.sprintf)(/* translators: accessibility text */ /* translators: accessibility text */ (0,t.__)("Move up (%s)","preferred-languages"),/* translators: keyboard shortcut (Arrow Up) */ /* translators: keyboard shortcut (Arrow Up) */ (0,t.__)("Up","preferred-languages")),label:/* translators: keyboard shortcut (Arrow Up) */ /* translators: keyboard shortcut (Arrow Up) */ (0,t.__)("Up","preferred-languages"),disabled:i,onClick:r,children:(0,t.__)("Move Up","preferred-languages")})}),(0,g.jsx)("li",{children:(0,g.jsx)(s.Button,{variant:"secondary",showTooltip:!0,"aria-keyshortcuts":"Alt+ArrowDown","aria-label":(0,t.sprintf)(/* translators: accessibility text */ /* translators: accessibility text */ (0,t.__)("Move down (%s)","preferred-languages"),/* translators: keyboard shortcut (Arrow Down) */ /* translators: keyboard shortcut (Arrow Down) */ (0,t.__)("Down","preferred-languages")),label:/* translators: keyboard shortcut (Arrow Down) */ /* translators: keyboard shortcut (Arrow Down) */ (0,t.__)("Down","preferred-languages"),disabled:c,onClick:n,children:(0,t.__)("Move Down","preferred-languages")})}),(0,g.jsx)("li",{children:(0,g.jsx)(s.Button,{variant:"secondary",showTooltip:!0,"aria-keyshortcuts":"Delete","aria-label":(0,t.sprintf)(/* translators: accessibility text */ /* translators: accessibility text */ (0,t.__)("Remove from list (%s)","preferred-languages"),/* translators: keyboard shortcut (Delete / Backspace) */ /* translators: keyboard shortcut (Delete / Backspace) */ (0,t.__)("Delete","preferred-languages")),label:/* translators: keyboard shortcut (Delete / Backspace) */ /* translators: keyboard shortcut (Delete / Backspace) */ (0,t.__)("Delete","preferred-languages"),disabled:d,onClick:l,children:(0,t.__)("Remove","preferred-languages")})})]})})}const u=function({languages:e,setLanguages:r,showOptionSiteDefault:n=!1,selectedLanguage:l,setSelectedLanguage:s}){const u=(0,a.useRef)(),p=0===e.length;(0,a.useLayoutEffect)((()=>{const e=u.current.querySelector('[aria-selected="true"]');e&&e.scrollIntoView({behavior:"smooth",block:"nearest"})}),[l,e]),(0,o.useShortcut)("preferred-languages/select-first",(a=>{a.preventDefault(),p||s(e.at(0))})),(0,o.useShortcut)("preferred-languages/select-last",(a=>{a.preventDefault(),p||s(e.at(-1))})),(0,o.useShortcut)("preferred-languages/select-previous",(a=>{if(a.preventDefault(),p)return;const r=e.findIndex((({locale:e})=>e===l.locale));e[r-1]&&s(e[r-1])})),(0,o.useShortcut)("preferred-languages/select-next",(a=>{if(a.preventDefault(),p)return;const r=e.findIndex((({locale:e})=>e===l.locale));e[r+1]&&s(e[r+1])}));const f=p?"":l.locale,m=p?"active-locales-list empty-list":"active-locales-list";let h=(0,t.sprintf)(/* translators: %s: English (United States) */ /* translators: %s: English (United States) */ (0,t.__)("Falling back to %s.","preferred-languages"),"English (United States)");return n&&(h=(0,t.__)("Falling back to Site Default.","preferred-languages")),(0,g.jsxs)("div",{className:"active-locales wp-clearfix",children:[p&&(0,g.jsxs)("div",{className:"active-locales-empty-message",children:[(0,t.__)("Nothing set.","preferred-languages"),(0,g.jsx)("br",{}),h]}),(0,g.jsx)("ul",{role:"listbox","aria-labelledby":"preferred-languages-label",tabIndex:0,"aria-activedescendant":f,className:m,ref:u,children:e.map((e=>{const{locale:a,nativeName:r,lang:n}=e;return(0,g.jsx)("li",{role:"option","aria-selected":a===l?.locale,id:a,lang:n,className:"active-locale",onClick:()=>s(e),children:r},a)}))}),(0,g.jsx)(d,{languages:e,selectedLanguage:l,onMoveUp:()=>{r((e=>{const a=e.findIndex((({locale:e})=>e===l.locale));return c(Array.from(e),a,a-1)})),(0,i.speak)((0,t.__)("Locale moved up","preferred-languages"))},onMoveDown:()=>{r((e=>{const a=e.findIndex((({locale:e})=>e===l.locale));return c(Array.from(e),a,a+1)})),(0,i.speak)((0,t.__)("Locale moved down","preferred-languages"))},onRemove:()=>{const a=e.findIndex((({locale:e})=>e===l.locale));if(s(e[a+1]||e[a-1]),r((e=>e.filter((({locale:e})=>e!==l.locale)))),(0,i.speak)((0,t.__)("Locale removed from list","preferred-languages")),1===e.length){let e=(0,t.sprintf)(/* translators: %s: English (United States) */ /* translators: %s: English (United States) */ (0,t.__)("No languages selected. Falling back to %s.","preferred-languages"),"English (United States)");n&&(e=(0,t.__)("No languages selected. Falling back to Site Default.","preferred-languages")),(0,i.speak)(e)}}})]})},p=window.wp.keycodes;function f({installedLanguages:e,availableLanguages:a,value:r,onChange:n}){const l=e.length||a.length;return(0,g.jsxs)(s.SelectControl,{"aria-label":(0,t.__)("Inactive Locales","preferred-languages"),label:(0,t.__)("Inactive Locales","preferred-languages"),hideLabelFromVision:!0,value:r,onChange:n,disabled:!l,__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,children:[e.length>0&&(0,g.jsx)("optgroup",{label:(0,t._x)("Installed","translations","preferred-languages"),children:e.map((({locale:e,lang:a,nativeName:r})=>(0,g.jsx)("option",{value:e,lang:a,children:r},e)))}),a.length>0&&(0,g.jsx)("optgroup",{label:(0,t._x)("Available","translations","preferred-languages"),children:a.map((({locale:e,lang:a,nativeName:r})=>(0,g.jsx)("option",{value:e,lang:a,children:r},e)))})]})}function m({disabled:e,onClick:a}){return(0,o.useShortcut)("preferred-languages/add",(r=>{r.preventDefault(),e||a()})),(0,g.jsx)("div",{className:"inactive-locales-controls",children:(0,g.jsx)(s.Button,{variant:"secondary",showTooltip:!0,"aria-keyshortcuts":"Alt+A","aria-label":(0,t.sprintf)(/* translators: accessibility text. %s: keyboard shortcut. */ /* translators: accessibility text. %s: keyboard shortcut. */ (0,t._x)("Add to list (%s)","language","preferred-languages"),p.shortcutAriaLabel.alt("A")),label:p.displayShortcut.alt("A"),disabled:e,onClick:a,children:(0,t._x)("Add","language","preferred-languages")})})}const h=function({languages:e,onAddLanguage:r}){const[n,l]=(0,a.useState)(e[0]);(0,a.useEffect)((()=>{n||l(e[0])}),[n,e]);const s=e.filter((({installed:e})=>Boolean(e))),o=e.filter((({installed:e})=>!e));return(0,g.jsxs)("div",{className:"inactive-locales wp-clearfix",children:[(0,g.jsx)("div",{className:"inactive-locales-list",children:(0,g.jsx)(f,{installedLanguages:s,availableLanguages:o,value:n?.locale,onChange:a=>{l(e.find((e=>a===e.locale)))}})}),(0,g.jsx)(m,{onClick:()=>{r(n);const e=s.findIndex((({locale:e})=>e===n.locale)),a=o.findIndex((({locale:e})=>e===n.locale));let c;c=s[e+1],c||s[0]===n||(c=s[0]),c||(c=o[a+1],o[0]!==n&&(c=o[0])),l(c),(0,i.speak)((0,t.__)("Locale added to list","preferred-languages"))},disabled:!n})]})};function v(){return(0,g.jsx)(s.Notice,{status:"warning",isDismissible:!1,children:(0,t.__)("Some of the languages are not installed. Re-save changes to download translations.","preferred-languages")})}function _({preferredLanguages:e}){const a=e.filter((e=>Boolean(e))).map((({locale:e})=>e)).join(",");return(0,g.jsx)("input",{type:"hidden",name:"preferred_languages",value:a})}const w=function(e){const{allLanguages:r,hasMissingTranslations:n=!1,showOptionSiteDefault:s=!1}=e,{registerShortcut:i}=(0,l.useDispatch)(o.store);(0,a.useEffect)((()=>{i({name:"preferred-languages/select-previous",category:"global",description:(0,t.__)("Select previous language","preferred-languages"),keyCombination:{character:"ArrowUp"}}),i({name:"preferred-languages/select-next",category:"global",description:(0,t.__)("Select next language","preferred-languages"),keyCombination:{character:"ArrowDown"}}),i({name:"preferred-languages/move-up",category:"global",description:(0,t.__)("Move language up","preferred-languages"),keyCombination:{character:"ArrowUp",modifier:"alt"}}),i({name:"preferred-languages/move-down",category:"global",description:(0,t.__)("Move language down","preferred-languages"),keyCombination:{character:"ArrowDown",modifier:"alt"}}),i({name:"preferred-languages/select-first",category:"global",description:(0,t.__)("Select first language","preferred-languages"),keyCombination:{character:"Home"}}),i({name:"preferred-languages/select-last",category:"global",description:(0,t.__)("Select last language","preferred-languages"),keyCombination:{character:"End"}}),i({name:"preferred-languages/remove",category:"global",description:(0,t.__)("Remove from list","preferred-languages"),keyCombination:{character:"Backspace"}}),i({name:"preferred-languages/add",category:"global",description:(0,t._x)("Add to list","language","preferred-languages"),keyCombination:{modifier:"alt",character:"a"}})}));const[c,d]=(0,a.useState)(e.preferredLanguages),[p,f]=(0,a.useState)(e.preferredLanguages[0]),m=r.filter((e=>!c.find((({locale:a})=>a===e.locale)))),w=c.some((({installed:e})=>!e));return(0,a.useEffect)((()=>{if(!w)return;const e=()=>{const e=document.createElement("span");e.className="spinner language-install-spinner is-active preferred-languages-spinner";const a=document.querySelector("#submit");a&&a.after(e)},a=document.querySelector("form");return a?(a.addEventListener("submit",e),()=>{a.removeEventListener("submit",e)}):void 0}),[w]),(0,g.jsx)(o.ShortcutProvider,{children:(0,g.jsxs)("div",{className:"preferred-languages",children:[(0,g.jsx)(_,{preferredLanguages:c}),(0,g.jsx)("p",{children:(0,t.__)("Choose languages for displaying WordPress in, in order of preference.","preferred-languages")}),(0,g.jsx)(u,{languages:c,setLanguages:d,showOptionSiteDefault:s,selectedLanguage:p,setSelectedLanguage:f}),(0,g.jsx)(h,{languages:m,onAddLanguage:e=>{d((a=>[...a,e])),f(e)}}),n&&(0,g.jsx)(v,{})]})})};n()((()=>{const e=window.PreferredLanguages;if(!e.allLanguages.length)return document.querySelector(".site-preferred-languages-wrap").remove(),void document.querySelector(".network-preferred-languages-wrap").remove();const r=document.querySelector("#preferred-languages-root");document.querySelector(".user-language-wrap")?.replaceWith(r.parentElement.parentElement),document.querySelector(".options-general-php #WPLANG")?.parentElement?.parentElement?.replaceWith(r.parentElement.parentElement),document.querySelector(".network-admin.settings-php #WPLANG")?.parentElement?.parentElement?.replaceWith(r.parentElement.parentElement),(0,a.createRoot)(r).render((0,g.jsx)(a.StrictMode,{children:(0,g.jsx)(w,{...e})}))}))})();