import L from"path";import{DEFAULT_LOCALE_PLACEHOLDER as f,TRANSLATIONS_FILE_NAME as h}from"../../../constants/index.js";import{I18N_DIR_NAME as w,L10N_DIR_NAME as A}from"../../constants/common.js";import{EntitlementsProvider as g}from"../../entitlements/entitlements-provider.js";import{logger as d,reporter as y}from"../../utils/index.js";import{defaultTranslations as E}from"../../../shared/l10n/default-translations.js";import{isL10nPath as I}from"../../fs/utils/is-l10n-path.js";import{isOpenapiDoc as P}from"../openapi-docs/is-openapi-doc.js";async function $(){return{id:"l10n",async processContent(n,a){const{fs:i,cache:t,getConfig:l}=a,e={},r=g.instance(),c=await l(),s=c.l10n?.defaultLocale||f;if(r.canAccessFeature("l10n")){await O(a);for(const{relativePath:o}of await i.scan(/(^|.*[\/\\])translations\.yaml$/)){const p=await t.load(o,"yaml"),u=F(o)||s;e[u]={translation:p.data}}}e[s]={translation:{...E,...e[s]?.translation}};const m=c.l10n?.locales||[f,...i.localeFolders].map(o=>({code:o.toLowerCase(),name:o}));n.setGlobalData({l10n:{translations:e,defaultLocale:s,locales:m.map(o=>({code:o.code,name:o.name||o.code}))}})}}}function F(n){return n.indexOf("/")>0?n.split("/")[1]:void 0}async function O(n){const a=await n.fs.scan();for(const{isVirtual:i,realRelativePath:t}of a){if(i)continue;if(I(t)&&t.endsWith(".page.tsx")&&y.panicOnBuild(`The file %rp is not allowed in ${A} or ${w} folders`,t),L.posix.basename(t)===h){const e=/^(?:@(i18n|l10n)[\/\\][^\/\\]+[\/\\])?translations\.yaml$/.test(t),r=await P(t,n);!e&&!r&&d.warn("The file %rp is in the wrong location. Make sure it is located in the root directory or in the locale root directory.",t),e&&r&&d.warn("It looks like the file %rp might be an OpenAPI definition and is located in a location reserved for translation files. Please rename it or move to another directory if it is not a translations file",t)}}}export{$ as l10nPlugin};
