From 5579f4b482c0b5350a1468432522f9e16f4bf4fd Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 19 Jan 2020 16:23:04 -0500 Subject: [PATCH] Automatically update translation report. Fixes #439 --- README.md | 25 +++++++++------- ui/package.json | 2 +- ui/translation_report.ts | 65 ++++++++++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index dca79913..51bd0476 100644 --- a/README.md +++ b/README.md @@ -153,24 +153,27 @@ If you'd like to add translations, take a look a look at the [English translatio - Languages supported: English (`en`), Chinese (`zh`), Dutch (`nl`), Esperanto (`eo`), French (`fr`), Spanish (`es`), Swedish (`sv`), German (`de`), Russian (`ru`), Italian (`it`). + + lang | done | missing --- | --- | --- -de | 94% | avatar,upload_avatar,show_avatars,docs,old_password,send_notifications_to_email,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,email_already_exists -eo | 81% | number_of_communities,preview,upload_image,avatar,upload_avatar,show_avatars,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,theme,are_you_sure,yes,no,email_already_exists -es | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,email_already_exists -fr | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,email_already_exists -it | 90% | avatar,upload_avatar,show_avatars,archive_link,docs,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,email_already_exists -nl | 100% | email_already_exists -ru | 77% | cross_posts,cross_post,number_of_communities,preview,upload_image,avatar,upload_avatar,show_avatars,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,recent_comments,theme,monero,by,to,transfer_community,transfer_site,are_you_sure,yes,no,email_already_exists -sv | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,email_already_exists -zh | 75% | cross_posts,cross_post,users,number_of_communities,preview,upload_image,avatar,upload_avatar,show_avatars,formatting_help,view_source,sticky,unsticky,archive_link,settings,stickied,delete_account,delete_account_confirm,banned,creator,number_online,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,recent_comments,nsfw,show_nsfw,theme,monero,by,to,transfer_community,transfer_site,are_you_sure,yes,no,email_already_exists - +de | 93% | avatar,upload_avatar,show_avatars,docs,old_password,send_notifications_to_email,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,donate_to_lemmy,donate,email_already_exists +eo | 80% | number_of_communities,preview,upload_image,avatar,upload_avatar,show_avatars,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,theme,donate_to_lemmy,donate,are_you_sure,yes,no,email_already_exists +es | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,donate_to_lemmy,donate,email_already_exists +fr | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,donate_to_lemmy,donate,email_already_exists +it | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,donate_to_lemmy,donate,email_already_exists +nl | 99% | donate_to_lemmy,donate,email_already_exists +ru | 77% | cross_posts,cross_post,number_of_communities,preview,upload_image,avatar,upload_avatar,show_avatars,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,recent_comments,theme,donate_to_lemmy,donate,monero,by,to,transfer_community,transfer_site,are_you_sure,yes,no,email_already_exists +sv | 89% | avatar,upload_avatar,show_avatars,archive_link,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,donate_to_lemmy,donate,email_already_exists +zh | 75% | cross_posts,cross_post,users,number_of_communities,preview,upload_image,avatar,upload_avatar,show_avatars,formatting_help,view_source,sticky,unsticky,archive_link,settings,stickied,delete_account,delete_account_confirm,banned,creator,number_online,docs,replies,mentions,old_password,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,send_notifications_to_email,language,browser_default,downvotes_disabled,enable_downvotes,open_registration,registration_closed,enable_nsfw,recent_comments,nsfw,show_nsfw,theme,donate_to_lemmy,donate,monero,by,to,transfer_community,transfer_site,are_you_sure,yes,no,email_already_exists + + If you'd like to update this report, run: ```bash cd ui -ts-node translation_report.ts > tmp # And replace the text above. +ts-node translation_report.ts ``` ## Credits diff --git a/ui/package.json b/ui/package.json index a2767e4a..ea6343da 100644 --- a/ui/package.json +++ b/ui/package.json @@ -57,7 +57,7 @@ "engineStrict": true, "husky": { "hooks": { - "pre-commit": "cargo clippy --manifest-path ../server/Cargo.toml --all-targets --all-features -- -D warnings && lint-staged" + "pre-commit": "ts-node translation_report.ts && git add ../README.md && cargo clippy --manifest-path ../server/Cargo.toml --all-targets --all-features -- -D warnings && lint-staged" } }, "lint-staged": { diff --git a/ui/translation_report.ts b/ui/translation_report.ts index 1975cfa5..71a09559 100644 --- a/ui/translation_report.ts +++ b/ui/translation_report.ts @@ -8,31 +8,50 @@ import { sv } from './src/translations/sv'; import { ru } from './src/translations/ru'; import { nl } from './src/translations/nl'; import { it } from './src/translations/it'; +import fs from 'fs'; -let files = [ - { t: de, n: 'de' }, - { t: eo, n: 'eo' }, - { t: es, n: 'es' }, - { t: fr, n: 'fr' }, - { t: it, n: 'it' }, - { t: nl, n: 'nl' }, - { t: ru, n: 'ru' }, - { t: sv, n: 'sv' }, - { t: zh, n: 'zh' }, -]; -let masterKeys = Object.keys(en.translation); - -let report = 'lang | done | missing\n'; -report += '--- | --- | ---\n'; - -for (let file of files) { - let keys = Object.keys(file.t.translation); - let pct: number = (keys.length / masterKeys.length) * 100; - let missing = difference(masterKeys, keys); - report += `${file.n} | ${pct.toFixed(0)}% | ${missing} \n`; -} +let readmePath = '../README.md'; + +let open = ''; +let close = ''; + +let readmeTxt = fs.readFileSync(readmePath, { encoding: 'utf8' }); + +let before = readmeTxt.split(open)[0]; +let after = readmeTxt.split(close)[1]; + +let report = buildReport(); + +let alteredReadmeTxt = `${before}${open}\n\n${report}\n${close}${after}`; -console.log(report); +fs.writeFileSync(readmePath, alteredReadmeTxt); + +function buildReport(): string { + let files = [ + { t: de, n: 'de' }, + { t: eo, n: 'eo' }, + { t: es, n: 'es' }, + { t: fr, n: 'fr' }, + { t: it, n: 'it' }, + { t: nl, n: 'nl' }, + { t: ru, n: 'ru' }, + { t: sv, n: 'sv' }, + { t: zh, n: 'zh' }, + ]; + let masterKeys = Object.keys(en.translation); + + let report = 'lang | done | missing\n'; + report += '--- | --- | ---\n'; + + for (let file of files) { + let keys = Object.keys(file.t.translation); + let pct: number = (keys.length / masterKeys.length) * 100; + let missing = difference(masterKeys, keys); + report += `${file.n} | ${pct.toFixed(0)}% | ${missing} \n`; + } + + return report; +} function difference(a: Array, b: Array): Array { return a.filter(x => !b.includes(x)); -- 2.44.1