-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
17 changed files
with
136 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import fs from "node:fs" | ||
import path from "node:path" | ||
|
||
type LanguageCompletion = Record<string, number> | ||
|
||
function getLanguageFiles(dir: string): string[] { | ||
return fs.readdirSync(dir).filter((file) => file.endsWith(".json")) | ||
} | ||
|
||
function getNamespaces(localesDir: string): string[] { | ||
return fs | ||
.readdirSync(localesDir) | ||
.filter((file) => fs.statSync(path.join(localesDir, file)).isDirectory()) | ||
} | ||
|
||
function countKeys(obj: any): number { | ||
let count = 0 | ||
for (const key in obj) { | ||
if (typeof obj[key] === "object") { | ||
count += countKeys(obj[key]) | ||
} else { | ||
count++ | ||
} | ||
} | ||
return count | ||
} | ||
|
||
function calculateCompleteness(localesDir: string): LanguageCompletion { | ||
const namespaces = getNamespaces(localesDir) | ||
const languages = new Set<string>() | ||
const keyCount: Record<string, number> = {} | ||
|
||
namespaces.forEach((namespace) => { | ||
const namespaceDir = path.join(localesDir, namespace) | ||
const files = getLanguageFiles(namespaceDir) | ||
|
||
files.forEach((file) => { | ||
const lang = path.basename(file, ".json") | ||
languages.add(lang) | ||
|
||
const content = JSON.parse(fs.readFileSync(path.join(namespaceDir, file), "utf-8")) | ||
keyCount[lang] = (keyCount[lang] || 0) + countKeys(content) | ||
}) | ||
}) | ||
|
||
const enCount = keyCount["en"] || 0 | ||
const completeness: LanguageCompletion = {} | ||
|
||
languages.forEach((lang) => { | ||
if (lang !== "en") { | ||
const percent = Math.round((keyCount[lang] / enCount) * 100) | ||
completeness[lang] = percent | ||
} | ||
}) | ||
|
||
return completeness | ||
} | ||
|
||
const i18n = calculateCompleteness(path.resolve(__dirname, "../locales")) | ||
export default i18n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"app.copied_to_clipboard": "Copied to clipboard", | ||
"cancel": "Cancel", | ||
"confirm": "Confirm", | ||
"ok": "OK", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"app.copied_to_clipboard": "クリップボードにコピーしました", | ||
"cancel": "キャンセル", | ||
"confirm": "確認", | ||
"ok": "OK", | ||
"quantifier.piece": "個", | ||
"time.last_night": "昨夜", | ||
"time.the_night_before_last": "一昨夜", | ||
"time.today": "今日", | ||
"time.yesterday": "昨日", | ||
"tips.load-lng-error": "言語パックの読み込みに失敗しました", | ||
"words.back": "戻る", | ||
"words.copy": "コピー", | ||
"words.edit": "編集", | ||
"words.entry": "エントリー", | ||
"words.id": "ID", | ||
"words.items_one": "アイテム", | ||
"words.items_other": "アイテム", | ||
"words.local": "ローカル", | ||
"words.record": "記録", | ||
"words.record_one": "記録", | ||
"words.record_other": "記録", | ||
"words.result": "結果", | ||
"words.result_one": "結果", | ||
"words.result_other": "結果", | ||
"words.space": "", | ||
"words.which.all": "すべて" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"app.copied_to_clipboard": "已复制到剪贴板", | ||
"cancel": "取消", | ||
"confirm": "确认", | ||
"ok": "好", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"langs.en": "English", | ||
"langs.zh-CN": "简体中文(部分完成)", | ||
"langs.ja": "日本語", | ||
"langs.zh-CN": "简体中文", | ||
"name": "English" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"langs.en": "English", | ||
"langs.ja": "日本語", | ||
"langs.zh-CN": "简体中文", | ||
"name": "日本語" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"langs.en": "English", | ||
"langs.zh-CN": "简体中文(部分完成)", | ||
"name": "English" | ||
"langs.ja": "日本語", | ||
"langs.zh-CN": "简体中文", | ||
"name": "简体中文" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters