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 | 23 ++++++++------- ui/package.json | 2 +- ui/translation_report.ts | 61 ++++++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index dca799132..51bd04769 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 a2767e4a5..ea6343da9 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 1975cfa5d..71a095593 100644 --- a/ui/translation_report.ts +++ b/ui/translation_report.ts @@ -8,32 +8,51 @@ 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 readmePath = '../README.md'; -let report = 'lang | done | missing\n'; -report += '--- | --- | ---\n'; +let open = ''; +let close = ''; -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 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}`; + +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; } -console.log(report); - function difference(a: Array, b: Array): Array { return a.filter(x => !b.includes(x)); }