[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-f18837c7-2c69-482d-97ca-5c0d7de4f3ee":3,"$faZ28oArncnsk89RfMmJAk_7jBjNaO8HdDjWqWUxo23k":42},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":33},"f18837c7-2c69-482d-97ca-5c0d7de4f3ee","azure-ai-translation-ts","基于REST风格的客户端进行文本和文档翻译。","cat_coding_backend","mod_coding","sickn33,coding","---\nname: azure-ai-translation-ts\ndescription: \"Text and document translation with REST-style clients.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure Translation SDKs for TypeScript\n\nText and document translation with REST-style clients.\n\n## Installation\n\n```bash\n# Text translation\nnpm install @azure-rest\u002Fai-translation-text @azure\u002Fidentity\n\n# Document translation\nnpm install @azure-rest\u002Fai-translation-document @azure\u002Fidentity\n```\n\n## Environment Variables\n\n```bash\nTRANSLATOR_ENDPOINT=https:\u002F\u002Fapi.cognitive.microsofttranslator.com\nTRANSLATOR_SUBSCRIPTION_KEY=\u003Cyour-api-key>\nTRANSLATOR_REGION=\u003Cyour-region>  # e.g., westus, eastus\n```\n\n## Text Translation Client\n\n### Authentication\n\n```typescript\nimport TextTranslationClient, { TranslatorCredential } from \"@azure-rest\u002Fai-translation-text\";\n\n\u002F\u002F API Key + Region\nconst credential: TranslatorCredential = {\n  key: process.env.TRANSLATOR_SUBSCRIPTION_KEY!,\n  region: process.env.TRANSLATOR_REGION!,\n};\nconst client = TextTranslationClient(process.env.TRANSLATOR_ENDPOINT!, credential);\n\n\u002F\u002F Or just credential (uses global endpoint)\nconst client2 = TextTranslationClient(credential);\n```\n\n### Translate Text\n\n```typescript\nimport TextTranslationClient, { isUnexpected } from \"@azure-rest\u002Fai-translation-text\";\n\nconst response = await client.path(\"\u002Ftranslate\").post({\n  body: {\n    inputs: [\n      {\n        text: \"Hello, how are you?\",\n        language: \"en\",  \u002F\u002F source (optional, auto-detect)\n        targets: [\n          { language: \"es\" },\n          { language: \"fr\" },\n        ],\n      },\n    ],\n  },\n});\n\nif (isUnexpected(response)) {\n  throw response.body.error;\n}\n\nfor (const result of response.body.value) {\n  for (const translation of result.translations) {\n    console.log(`${translation.language}: ${translation.text}`);\n  }\n}\n```\n\n### Translate with Options\n\n```typescript\nconst response = await client.path(\"\u002Ftranslate\").post({\n  body: {\n    inputs: [\n      {\n        text: \"Hello world\",\n        language: \"en\",\n        textType: \"Plain\",  \u002F\u002F or \"Html\"\n        targets: [\n          {\n            language: \"de\",\n            profanityAction: \"NoAction\",  \u002F\u002F \"Marked\" | \"Deleted\"\n            tone: \"formal\",  \u002F\u002F LLM-specific\n          },\n        ],\n      },\n    ],\n  },\n});\n```\n\n### Get Supported Languages\n\n```typescript\nconst response = await client.path(\"\u002Flanguages\").get();\n\nif (isUnexpected(response)) {\n  throw response.body.error;\n}\n\n\u002F\u002F Translation languages\nfor (const [code, lang] of Object.entries(response.body.translation || {})) {\n  console.log(`${code}: ${lang.name} (${lang.nativeName})`);\n}\n```\n\n### Transliterate\n\n```typescript\nconst response = await client.path(\"\u002Ftransliterate\").post({\n  body: { inputs: [{ text: \"这是个测试\" }] },\n  queryParameters: {\n    language: \"zh-Hans\",\n    fromScript: \"Hans\",\n    toScript: \"Latn\",\n  },\n});\n\nif (!isUnexpected(response)) {\n  for (const t of response.body.value) {\n    console.log(`${t.script}: ${t.text}`);  \u002F\u002F Latn: zhè shì gè cè shì\n  }\n}\n```\n\n### Detect Language\n\n```typescript\nconst response = await client.path(\"\u002Fdetect\").post({\n  body: { inputs: [{ text: \"Bonjour le monde\" }] },\n});\n\nif (!isUnexpected(response)) {\n  for (const result of response.body.value) {\n    console.log(`Language: ${result.language}, Score: ${result.score}`);\n  }\n}\n```\n\n## Document Translation Client\n\n### Authentication\n\n```typescript\nimport DocumentTranslationClient from \"@azure-rest\u002Fai-translation-document\";\nimport { DefaultAzureCredential } from \"@azure\u002Fidentity\";\n\nconst endpoint = \"https:\u002F\u002F\u003Ctranslator>.cognitiveservices.azure.com\";\n\n\u002F\u002F TokenCredential\nconst client = DocumentTranslationClient(endpoint, new DefaultAzureCredential());\n\n\u002F\u002F API Key\nconst client2 = DocumentTranslationClient(endpoint, { key: \"\u003Capi-key>\" });\n```\n\n### Single Document Translation\n\n```typescript\nimport DocumentTranslationClient from \"@azure-rest\u002Fai-translation-document\";\nimport { writeFile } from \"node:fs\u002Fpromises\";\n\nconst response = await client.path(\"\u002Fdocument:translate\").post({\n  queryParameters: {\n    targetLanguage: \"es\",\n    sourceLanguage: \"en\",  \u002F\u002F optional\n  },\n  contentType: \"multipart\u002Fform-data\",\n  body: [\n    {\n      name: \"document\",\n      body: \"Hello, this is a test document.\",\n      filename: \"test.txt\",\n      contentType: \"text\u002Fplain\",\n    },\n  ],\n}).asNodeStream();\n\nif (response.status === \"200\") {\n  await writeFile(\"translated.txt\", response.body);\n}\n```\n\n### Batch Document Translation\n\n```typescript\nimport { ContainerSASPermissions, BlobServiceClient } from \"@azure\u002Fstorage-blob\";\n\n\u002F\u002F Generate SAS URLs for source and target containers\nconst sourceSas = await sourceContainer.generateSasUrl({\n  permissions: ContainerSASPermissions.parse(\"rl\"),\n  expiresOn: new Date(Date.now() + 24 * 60 * 60 * 1000),\n});\n\nconst targetSas = await targetContainer.generateSasUrl({\n  permissions: ContainerSASPermissions.parse(\"rwl\"),\n  expiresOn: new Date(Date.now() + 24 * 60 * 60 * 1000),\n});\n\n\u002F\u002F Start batch translation\nconst response = await client.path(\"\u002Fdocument\u002Fbatches\").post({\n  body: {\n    inputs: [\n      {\n        source: { sourceUrl: sourceSas },\n        targets: [\n          { targetUrl: targetSas, language: \"fr\" },\n        ],\n      },\n    ],\n  },\n});\n\n\u002F\u002F Get operation ID from header\nconst operationId = new URL(response.headers[\"operation-location\"])\n  .pathname.split(\"\u002F\").pop();\n```\n\n### Get Translation Status\n\n```typescript\nimport { isUnexpected, paginate } from \"@azure-rest\u002Fai-translation-document\";\n\nconst statusResponse = await client.path(\"\u002Fdocument\u002Fbatches\u002F{id}\", operationId).get();\n\nif (!isUnexpected(statusResponse)) {\n  const status = statusResponse.body;\n  console.log(`Status: ${status.status}`);\n  console.log(`Total: ${status.summary.total}`);\n  console.log(`Success: ${status.summary.success}`);\n}\n\n\u002F\u002F List documents with pagination\nconst docsResponse = await client.path(\"\u002Fdocument\u002Fbatches\u002F{id}\u002Fdocuments\", operationId).get();\nconst documents = paginate(client, docsResponse);\n\nfor await (const doc of documents) {\n  console.log(`${doc.id}: ${doc.status}`);\n}\n```\n\n### Get Supported Formats\n\n```typescript\nconst response = await client.path(\"\u002Fdocument\u002Fformats\").get();\n\nif (!isUnexpected(response)) {\n  for (const format of response.body.value) {\n    console.log(`${format.format}: ${format.fileExtensions.join(\", \")}`);\n  }\n}\n```\n\n## Key Types\n\n```typescript\n\u002F\u002F Text Translation\nimport type {\n  TranslatorCredential,\n  TranslatorTokenCredential,\n} from \"@azure-rest\u002Fai-translation-text\";\n\n\u002F\u002F Document Translation\nimport type {\n  DocumentTranslateParameters,\n  StartTranslationDetails,\n  TranslationStatus,\n} from \"@azure-rest\u002Fai-translation-document\";\n```\n\n## Best Practices\n\n1. **Auto-detect source** - Omit `language` parameter to auto-detect\n2. **Batch requests** - Translate multiple texts in one call for efficiency\n3. **Use SAS tokens** - For document translation, use time-limited SAS URLs\n4. **Handle errors** - Always check `isUnexpected(response)` before accessing body\n5. **Regional endpoints** - Use regional endpoints for lower latency\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,90,648,"2026-05-16 13:05:32",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":25,"skillCount":32,"createdAt":26},"后端开发","backend","mdi-server","API、数据库、服务端架构",296,[34],{"id":35,"skillId":4,"version":36,"fileName":37,"fileSize":38,"filePath":39,"fileHash":40,"manifest":41,"createdAt":19},"2dea23ed-a9d5-4bf7-9c26-965e8125d3ec","1.0.0","azure-ai-translation-ts.zip",2547,"uploads\u002Fskills\u002Ff18837c7-2c69-482d-97ca-5c0d7de4f3ee\u002Fazure-ai-translation-ts.zip","8202dee3d1a30c28664c19da4a287b8c980596ce4d9641a9f419a87f547215a8","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":7453}]",{"code":43,"message":44,"data":45},200,"success",{"items":46,"stats":47,"page":50},[],{"averageRating":48,"totalRatings":48,"ratingCounts":49},0,[48,48,48,48,48],{"limit":51,"offset":48,"hasMore":52,"nextOffset":51,"ratedOnly":16},15,false]