]> Untitled Git - lemmy.git/commitdiff
Automatically update translation report. Fixes #439
authorDessalines <tyhou13@gmx.com>
Sun, 19 Jan 2020 21:23:04 +0000 (16:23 -0500)
committerDessalines <tyhou13@gmx.com>
Sun, 19 Jan 2020 21:23:04 +0000 (16:23 -0500)
README.md
ui/package.json
ui/translation_report.ts

index dca7991325d35c1ab4aeb014c7f41a9180ae69c2..51bd047692625fe492095e796667733f8d9a7eef 100644 (file)
--- 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`).
 
+<!-- translations -->
+
 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 
+
+<!-- translationsstop -->
 
 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
index a2767e4a525fc1e8b6bcb32203228a9c0fd2b6b8..ea6343da9afcf9fe51be1e7b4347d1f2e77214e5 100644 (file)
@@ -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": {
index 1975cfa5d6c42432bf29e8c83c18f6e8483943db..71a095593180196d86e3319832e087a6d2df60fe 100644 (file)
@@ -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 = '<!-- translations -->';
+let close = '<!-- translationsstop -->';
+
+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<string>, b: Array<string>): Array<string> {
   return a.filter(x => !b.includes(x));