Skip to content

Commit 43608fb

Browse files
authored
feat: 翻訳状態にオリジナルコンテンツを追加 (#188)
1 parent c7f3482 commit 43608fb

File tree

10 files changed

+65
-30
lines changed

10 files changed

+65
-30
lines changed

docs/glossary.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ description: |
55

66
# 用語集
77

8-
<div class="info-box">
9-
<p>このページの内容は公式ドキュメントには含まれておらず、日本語コミュニティによって独自に追加されたものです。</p>
10-
</div>
11-
128
以下は翻訳時に使用される英日対照の用語集です。
139

1410
| 英語 | 日本語 | 備考 |

docs/japanese/articles.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ description: |
55

66
# 日本語記事
77

8-
<div class="info-box">
9-
<p>このページの内容は公式ドキュメントには含まれておらず、日本語コミュニティによって独自に追加されたものです。</p>
10-
</div>
11-
128
Typstに関する日本語の記事は[Zenn](https://zenn.dev/)[Qiita](https://qiita.com/)に沢山掲載されています。以下のリンクからその一覧が見られます。
139

1410
- [Typstの記事一覧 | Zenn](https://zenn.dev/topics/typst) - ZennのTypstトピック

docs/japanese/packages.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,5 @@ description: |
55

66
# 日本語向けパッケージ
77

8-
<div class="info-box">
9-
<p>このページの内容は公式ドキュメントには含まれておらず、日本語コミュニティによって独自に追加されたものです。</p>
10-
</div>
11-
128
- [rubby](https://typst.app/universe/package/rubby) - ふりがなを振る
139
- [roremu](https://typst.app/universe/package/roremu) - 日本語のダミーテキストを生成する

docs/japanese/templates.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ description: |
55

66
# 日本語テンプレート
77

8-
<div class="info-box">
9-
<p>このページの内容は公式ドキュメントには含まれておらず、日本語コミュニティによって独自に追加されたものです。</p>
10-
</div>
11-
128
## 一般
139

1410
- [typst-jp-template](https://github.com/satshi/typst-jp-template) - pLaTeXでのjarticle風のとりあえず日本語で書き始めるためのテンプレート

docs/japanese/welcome.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ description: Typstの日本語組版のための情報を提供します。
44

55
# 日本語組版情報
66

7-
<div class="info-box">
8-
<p>このページの内容は公式ドキュメントには含まれておらず、日本語コミュニティによって独自に追加されたものです。</p>
9-
</div>
10-
117
このページでは、Typstで日本語組版を行うユーザー向けの情報を提供します。有益な情報をお持ちの方は、ぜひIssueやPull Requestを通じて貢献してください。
128

139
ここでは日本語に特化した情報を提供します。日本語だけに限らず、多言語を対象とする情報については、[Awesome Typst](https://github.com/qjcg/awesome-typst)などを参照してください。

website/src/components/ui/common/TranslationStatusAlert.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ const getStatusConfig = (status: TranslationStatus): StatusConfig => {
4343
message:
4444
"このページはまだ翻訳されていません。原文の内容が表示されています。",
4545
};
46+
case "community":
47+
return {
48+
bgColor: "bg-cyan-50",
49+
borderColor: "border-cyan-200",
50+
textColor: "text-cyan-800",
51+
iconColor: "text-cyan-600",
52+
label: "日本語版オリジナル",
53+
message:
54+
"このページの内容は公式ドキュメントには含まれておらず、日本語コミュニティが独自に追加したものです。",
55+
};
4656
}
4757
};
4858

website/src/utils/translationStatus.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,46 @@ describe("translationStatus", () => {
151151
expect(result).toBe(0.625);
152152
});
153153

154+
it("originalページは計算から除外される", async () => {
155+
const { calculateTranslationProgressRate } = await import(
156+
"./translationStatus"
157+
);
158+
159+
const status = {
160+
$schema: "./translation-status.schema.json",
161+
"/docs/page1/": "translated", // 1.0
162+
"/docs/page2/": "partially_translated", // 0.5
163+
"/docs/original1/": "community", // 除外
164+
"/docs/original2/": "community", // 除外
165+
"/docs/page3/": "untranslated", // 0.0
166+
};
167+
168+
mockFs.readFileSync.mockReturnValue(JSON.stringify(status));
169+
170+
const result = calculateTranslationProgressRate();
171+
172+
// (1.0 + 0.5 + 0.0) / 3 = 0.5
173+
expect(result).toBe(0.5);
174+
});
175+
176+
it("全てoriginalページの場合は0を返す", async () => {
177+
const { calculateTranslationProgressRate } = await import(
178+
"./translationStatus"
179+
);
180+
181+
const status = {
182+
$schema: "./translation-status.schema.json",
183+
"/docs/original1/": "community",
184+
"/docs/original2/": "community",
185+
};
186+
187+
mockFs.readFileSync.mockReturnValue(JSON.stringify(status));
188+
189+
const result = calculateTranslationProgressRate();
190+
191+
expect(result).toBe(0);
192+
});
193+
154194
it("ページが存在しない場合は0を返す", async () => {
155195
const { calculateTranslationProgressRate } = await import(
156196
"./translationStatus"

website/src/utils/translationStatus.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import path from "node:path";
44
export type TranslationStatus =
55
| "translated"
66
| "partially_translated"
7-
| "untranslated";
7+
| "untranslated"
8+
| "community";
89

910
export type TranslationStatusMap = {
1011
[route: string]: TranslationStatus;
@@ -67,19 +68,23 @@ export const registerRoutes = (routes: string[]): void => {
6768
/**
6869
* 翻訳の進捗率を計算する。
6970
* `translated`は1.0、`partially_translated`は0.5の重みを持つ。
71+
* `original`は翻訳対象外のため計算から除外される。
7072
* @returns [0.0, 1.0]の範囲で表される翻訳率
7173
*/
7274
export const calculateTranslationProgressRate = (): number => {
7375
const status = loadTranslationStatus();
7476
const routes = Object.keys(status).filter((key) => key !== "$schema");
77+
const translationTargetRoutes = routes.filter(
78+
(route) => status[route] !== "community",
79+
);
7580

76-
if (routes.length === 0) {
81+
if (translationTargetRoutes.length === 0) {
7782
return 0;
7883
}
7984

8085
let translationScore = 0;
8186

82-
for (const route of routes) {
87+
for (const route of translationTargetRoutes) {
8388
const currentStatus = status[route];
8489
if (currentStatus === "translated") {
8590
translationScore += 1;
@@ -88,7 +93,7 @@ export const calculateTranslationProgressRate = (): number => {
8893
}
8994
}
9095

91-
return translationScore / routes.length;
96+
return translationScore / translationTargetRoutes.length;
9297
};
9398

9499
let translationStatusCache: TranslationStatusMap | null = null;

website/translation-status.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@
187187
"/docs/changelog/0.2.0/": "untranslated",
188188
"/docs/changelog/0.1.0/": "untranslated",
189189
"/docs/changelog/earlier/": "untranslated",
190-
"/docs/japanese/": "translated",
191-
"/docs/japanese/templates/": "translated",
192-
"/docs/japanese/packages/": "translated",
193-
"/docs/japanese/articles/": "translated",
194-
"/docs/glossary/": "translated"
190+
"/docs/japanese/": "community",
191+
"/docs/japanese/templates/": "community",
192+
"/docs/japanese/packages/": "community",
193+
"/docs/japanese/articles/": "community",
194+
"/docs/glossary/": "community"
195195
}

website/translation-status.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"additionalProperties": {
1313
"type": "string",
14-
"enum": ["translated", "partially_translated", "untranslated"],
14+
"enum": ["translated", "partially_translated", "untranslated", "community"],
1515
"description": "ページの翻訳状態"
1616
}
1717
}

0 commit comments

Comments
 (0)