Skip to content

Commit

Permalink
feat(macros/AvailableInWorkers): support more distinct cases (#10029)
Browse files Browse the repository at this point in the history
  • Loading branch information
teoli2003 authored Mar 28, 2024
1 parent ad94d8a commit f38adb3
Showing 1 changed file with 55 additions and 24 deletions.
79 changes: 55 additions & 24 deletions kumascript/macros/AvailableInWorkers.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
//
// Parameters:
//
// $0 - workerType (optional)
//
// The optional first argument has to be one of the ['notservice'].
// $0 - workerType (optional):
// 'window_and_dedicated': only in DedicatedWorker (and in Window)
// 'dedicated': only in DedicatedWorker
// 'window_and_worker_except_service': all workers but ServiceWorker (and in Window)
// 'worker_except_service': all workers but ServiceWorker (and no window)
// 'window_and_service': only in ServiceWorker (and in Window)
// 'service': only in ServiceWorker
// null: (default) All workers (and Window)
//
// {{AvailableInWorkers}}
// {{AvailableInWorkers("notservice")}}
// {{AvailableInWorkers("worker_except_service")}}
//
const locale = env.locale;
Expand All @@ -21,38 +26,64 @@ const note = mdn.localString({
"ko": "참고:",
"ru": "Примечание:",
"zh-CN": "备注:",
"zh-TW": "備註:"
"zh-TW": "備註:",
});
const textDefault = mdn.localString({
"en-US": `This feature is available in <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>`,
"zh-CN": `此特性在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a> 中可用`,
"zh-TW": `此功能可在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a> 中使用`,
"es": `Esta característica está disponible en <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>`,
"fr": `Cette fonctionnalité est disponible via les <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>`,
"ja": `この機能は <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a> 内で利用可能です`,
"ko": `이 기능은 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a>에서 사용할 수 있습니다`,
"ru": `Эта возможность доступна в <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>`
"en-US": `This feature is available in <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>.`,
"zh-CN": `此特性在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a> 中可用。`,
"zh-TW": `此功能可在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a> 中使用。`,
"es": `Esta característica está disponible en <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>.`,
"fr": `Cette fonctionnalité est disponible via les <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>.`,
"ja": `この機能は <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a> 内で利用可能です。`,
"ko": `이 기능은 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a>에서 사용할 수 있습니다.`,
"ru": `Эта возможность доступна в <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>.`,
});
const textNotService = mdn.localString({
"en-US": `This feature is available in <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>, except for <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Workers</a>.`,
"zh-CN": `此特性在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a>(不包括 <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Worker</a>)中可用。`,
"zh-TW": `此功能可在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a>(不包括 <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Worker</a>)中使用。`,
});
const textNotServiceNotWindow = mdn.localString({
"en-US": `This feature is only available in <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>, except for <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Workers</a>.`,
});
const textDedicated = mdn.localString({
"en-US": `This feature is available in <a href="/${locale}/docs/Web/API/DedicatedWorkerGlobalScope">Dedicated Web Workers</a>.`,
});
const textDedicatedOnly = mdn.localString({
"en-US": `This feature is only available in <a href="/${locale}/docs/Web/API/DedicatedWorkerGlobalScope">Dedicated Web Workers</a>.`,
});
const textServiceWorkers = mdn.localString({
"en-US": `This feature is available in <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Workers</a>, except for <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Workers</a>`,
"zh-CN": `此特性在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a>(不包括 <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Worker</a>)中可用`,
"zh-TW": `此功能可在 <a href="/${locale}/docs/Web/API/Web_Workers_API">Web Worker</a>(不包括 <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Worker</a>)中使用`
const textService = mdn.localString({
"en-US": `This feature is available in <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Workers</a>.`,
});
const textServiceOnly = mdn.localString({
"en-US": `This feature is only available in <a href="/${locale}/docs/Web/API/Service_Worker_API">Service Workers</a>.`,
})
const workerType = $0;
const workerType = $0 || 'default';
let text = "";
const associatedText = {
default: () => textDefault,
window_and_worker_except_service: () => textNotService,
worker_except_service: () => textNotServiceNotWindow,
window_and_dedicated: () => textDedicated,
dedicated: () => textDedicatedOnly,
window_and_service: () => textService,
service: () => textServiceOnly,
};
if (workerType === "notservice") {
text = textServiceWorkers;
} else if (workerType) {
if (!associatedText[workerType]) {
throw new Error(`'${workerType}' is not a recognized argument to this macro`);
} else {
text = textDefault;
}
const text = associatedText[workerType]();
%>

<div class="notecard note">
Expand Down

0 comments on commit f38adb3

Please sign in to comment.