defter 0.7.2

Self-hosted Zotero sync and file storage server, with metadata in SQLite and attachments in S3.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
//! The public profile's languages. The wording follows the English and German
//! locales of commonmeta.org (dragoman's `ui/src/locales`), so a person's page
//! reads the same on both.

/// A language the public profile is available in.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Lang {
    En,
    De,
}

/// The words on the public profile.
pub struct Text {
    pub person: &'static str,
    pub given_name: &'static str,
    pub family_name: &'static str,
    pub additional_names: &'static str,
    pub websites: &'static str,
    pub country: &'static str,
    pub affiliations: &'static str,
    pub started: &'static str,
    pub ended: &'static str,
    pub filters: &'static str,
    pub facet_year: &'static str,
    pub facet_type: &'static str,
    pub facet_language: &'static str,
    pub facet_license: &'static str,
    pub open_all: &'static str,
    pub close_all: &'static str,
    pub clear_filters: &'static str,
    pub search: &'static str,
    pub search_placeholder: &'static str,
    pub copy_citation: &'static str,
    pub content: &'static str,
    pub published: &'static str,
    pub in_container: &'static str,
    pub license: &'static str,
    pub no_results: &'static str,
    pub no_works: &'static str,
    pub pagination: &'static str,
    pub previous_page: &'static str,
    pub next_page: &'static str,
    pub language: &'static str,
    pub apply: &'static str,
    pub featured_only: &'static str,
    pub clear: &'static str,
    pub export_format: &'static str,
    pub citation_style: &'static str,
    pub formatted_citation: &'static str,
    pub export: &'static str,
    pub copy: &'static str,
    pub copied: &'static str,
}

const EN: Text = Text {
    person: "Person",
    given_name: "Given name",
    family_name: "Family name",
    additional_names: "Also known as",
    websites: "Websites & social links",
    country: "Country",
    affiliations: "Affiliations",
    started: "Started",
    ended: "Ended at",
    filters: "Filters",
    facet_year: "Publication year",
    facet_type: "Content type",
    facet_language: "Language",
    facet_license: "License",
    open_all: "Open all",
    close_all: "Close all",
    clear_filters: "Clear filters",
    search: "Search",
    search_placeholder: "Search these works",
    copy_citation: "Copy citation",
    content: "Content",
    published: "published",
    in_container: "in",
    license: "Distributed under the terms of the",
    no_results: "No results found.",
    no_works: "No works on this page.",
    pagination: "Pagination",
    previous_page: "Previous page",
    next_page: "Next page",
    language: "Language",
    apply: "Apply",
    featured_only: "Featured only",
    clear: "Clear",
    export_format: "Export format",
    citation_style: "Citation style",
    formatted_citation: "Formatted Citation",
    export: "Export",
    copy: "Copy",
    copied: "Copied",
};

const DE: Text = Text {
    person: "Person",
    given_name: "Vorname",
    family_name: "Familienname",
    additional_names: "Auch bekannt als",
    websites: "Webseiten & soziale Netzwerke",
    country: "Land",
    affiliations: "Zugehörigkeiten",
    started: "Beginn",
    ended: "Ende",
    filters: "Filter",
    facet_year: "Erscheinungsjahr",
    facet_type: "Inhaltstyp",
    facet_language: "Sprache",
    facet_license: "Lizenz",
    open_all: "Alle öffnen",
    close_all: "Alle schließen",
    clear_filters: "Filter zurücksetzen",
    search: "Suche",
    search_placeholder: "Diese Werke durchsuchen",
    copy_citation: "Zitat kopieren",
    content: "Inhalt",
    published: "veröffentlicht",
    in_container: "in",
    license: "Veröffentlicht unter den Bedingungen der",
    no_results: "Keine Ergebnisse gefunden.",
    no_works: "Keine Werke auf dieser Seite.",
    pagination: "Seitennummerierung",
    previous_page: "Vorherige Seite",
    next_page: "Nächste Seite",
    language: "Sprache",
    apply: "Anwenden",
    featured_only: "Nur hervorgehobene",
    clear: "Löschen",
    export_format: "Exportformat",
    citation_style: "Zitierstil",
    formatted_citation: "Formatiertes Zitat",
    export: "Exportieren",
    copy: "Kopieren",
    copied: "Kopiert",
};

/// The words on the dashboard, the sign-in and the Zotero consent pages.
pub struct Pages {
    pub library: &'static str,
    pub library_version: &'static str,
    pub user: &'static str,
    pub items: &'static str,
    pub attachments: &'static str,
    pub notes: &'static str,
    pub collections: &'static str,
    pub tags: &'static str,
    pub in_trash: &'static str,
    pub files: &'static str,
    pub stored: &'static str,
    pub attachment_storage: &'static str,
    pub backups: &'static str,
    pub backup_last: &'static str,
    pub backup_never: &'static str,
    pub backup_off: &'static str,
    pub backup_failed: &'static str,
    pub backup_warning: &'static str,
    pub signed_downloads: &'static str,
    pub streamed_downloads: &'static str,
    pub files_up_to: &'static str,
    pub are_accepted: &'static str,
    pub public_profile: &'static str,
    pub profile_hidden: &'static str,
    pub profile_visible: &'static str,
    pub it_lists: &'static str,
    pub all_of_my_publications: &'static str,
    pub show_profile: &'static str,
    pub hide_profile: &'static str,
    pub connect_zotero: &'static str,
    pub connect_intro: &'static str,
    pub connect_download: &'static str,
    pub connect_install: &'static str,
    pub connect_server: &'static str,
    pub connect_login: &'static str,
    pub sync_heading: &'static str,
    pub sync_intro: &'static str,
    pub sync_enabled: &'static str,
    pub sync_pdf: &'static str,
    pub sync_publications: &'static str,
    pub sync_needs_orcid: &'static str,
    pub sync_deduplicate: &'static str,
    pub sync_overwrite: &'static str,
    pub sync_overwrite_hint: &'static str,
    pub sync_log: &'static str,
    pub sync_preview: &'static str,
    pub sync_now: &'static str,
    pub sync_running: &'static str,
    pub sync_busy: &'static str,
    pub sync_never: &'static str,
    pub sync_last: &'static str,
    pub sync_last_preview: &'static str,
    pub sync_details: &'static str,
    pub sync_more: &'static str,
    pub sync_ok: &'static str,
    pub sync_partial: &'static str,
    pub sync_failed: &'static str,
    pub sync_aborted: &'static str,
    pub sync_off: &'static str,
    pub sync_on: &'static str,
    pub sync_on_pdf: &'static str,
    pub sync_opted_in: &'static str,
    pub sync_newest: &'static str,
    pub sync_last_failed: &'static str,
    pub sign_in: &'static str,
    pub api_key: &'static str,
    pub key_holders: &'static str,
    pub needs_signing_in: &'static str,
    pub sign_in_with: &'static str,
    pub sign_in_with_end: &'static str,
    pub approve_with_end: &'static str,
    pub from_another_site: &'static str,
    pub not_a_key: &'static str,
    pub sign_in_failed: &'static str,
    pub no_orcid: &'static str,
    pub not_allowed: &'static str,
    pub ask_admin_email: &'static str,
    pub ask_admin: &'static str,
    pub connect_account: &'static str,
    pub connect_why: &'static str,
    pub connect_how: &'static str,
    pub connect_key_page: &'static str,
    pub connect_kept: &'static str,
    pub zotero_key: &'static str,
    pub connect: &'static str,
    pub zotero_key_rejected: &'static str,
    pub zotero_unreachable: &'static str,
    pub zotero_id_taken: &'static str,
    pub account_expired: &'static str,
    pub signing_out: &'static str,
    pub signed_out_here: &'static str,
    pub continue_signing_out: &'static str,
    pub authorize_zotero: &'static str,
    pub authorized: &'static str,
    pub login_expired: &'static str,
    pub no_login_request: &'static str,
    pub not_authorized: &'static str,
    pub pending_signed_in: &'static str,
    pub pending_sign_in: &'static str,
    pub pending_key: &'static str,
    pub return_to_zotero: &'static str,
    pub expired_message: &'static str,
    pub missing_message: &'static str,
    pub approve: &'static str,
    pub approval_from_another_site: &'static str,
    pub not_allowed_to_approve: &'static str,
    pub signed_in_as: &'static str,
    pub storage_used: &'static str,
    pub of: &'static str,
    pub no_limit: &'static str,
    pub over_quota: &'static str,
    pub devices: &'static str,
    pub devices_intro: &'static str,
    pub no_devices: &'static str,
    pub revoke: &'static str,
    pub added: &'static str,
    pub last_used: &'static str,
    pub never_used: &'static str,
    pub admin: &'static str,
    pub invites: &'static str,
    pub invites_intro: &'static str,
    pub no_invites: &'static str,
    pub invites_off: &'static str,
    pub access_claim: &'static str,
    pub access_users: &'static str,
    pub access_admins: &'static str,
    pub disabled_by_provider: &'static str,
    pub orcid_id: &'static str,
    pub note: &'static str,
    pub invite: &'static str,
    pub uninvite: &'static str,
    pub invite_used: &'static str,
    pub not_an_orcid: &'static str,
    pub already_a_user: &'static str,
    pub not_a_quota: &'static str,
    pub users: &'static str,
    pub quota_mb: &'static str,
    pub default_quota_is: &'static str,
    pub empty_for_no_limit: &'static str,
    pub save: &'static str,
    pub disable: &'static str,
    pub enable: &'static str,
    pub disabled: &'static str,
    pub owner: &'static str,
    pub you: &'static str,
    pub devices_count: &'static str,
    pub groups: &'static str,
    pub groups_intro: &'static str,
    pub no_groups: &'static str,
    pub group_name: &'static str,
    pub create_group: &'static str,
    pub group_description: &'static str,
    pub library_editing: &'static str,
    pub file_editing: &'static str,
    pub editing_members: &'static str,
    pub editing_admins: &'static str,
    pub editing_none: &'static str,
    pub members: &'static str,
    pub add_member: &'static str,
    pub add_member_intro: &'static str,
    pub role: &'static str,
    pub role_owner: &'static str,
    pub role_admin: &'static str,
    pub role_member: &'static str,
    pub make_admin: &'static str,
    pub make_member: &'static str,
    pub remove: &'static str,
    pub leave_group: &'static str,
    pub delete_group: &'static str,
    pub delete_group_note: &'static str,
    pub not_a_user_yet: &'static str,
    pub your_role: &'static str,
    pub back_to_library: &'static str,
    pub sign_in_to_approve: &'static str,
    pub key_only_reads: &'static str,
}

const PAGES_EN: Pages = Pages {
    library: "Library",
    library_version: "Library version",
    user: "user",
    items: "Items",
    attachments: "Attachments",
    notes: "Notes",
    collections: "Collections",
    tags: "Tags",
    in_trash: "In trash",
    files: "Files",
    stored: "Stored",
    attachment_storage: "Attachment storage",
    backups: "Backups",
    backup_last: "Last backup:",
    backup_never: "No backup has run since the server started.",
    backup_off: "Scheduled backups are off.",
    backup_failed: "The last backup failed:",
    backup_warning: "With a warning:",
    signed_downloads: "Clients download files directly from the bucket through pre-signed URLs.",
    streamed_downloads: "Downloads are streamed through this server.",
    files_up_to: "Files up to",
    are_accepted: "are accepted.",
    public_profile: "Public profile",
    profile_hidden: "Hidden: the address answers \"not found\".",
    profile_visible: "Visible to anyone.",
    it_lists: "It lists",
    all_of_my_publications: ": everything in My Publications in Zotero.",
    show_profile: "Show profile",
    hide_profile: "Hide profile",
    connect_zotero: "Connect Zotero",
    connect_intro: "defter works beside zotero.org: Zotero keeps syncing with zotero.org and \
                    Zotero Storage, and the defter for Zotero plugin also syncs your library \
                    with this server. Requires Zotero 10.",
    connect_download: "Download",
    connect_install: " and install it in Zotero under Tools → Plugins → gear menu → Install \
                      Plugin From File…",
    connect_server: "In Zotero, open Settings → defter and enter this server:",
    connect_login: "Click Log in, approve the login on this server, then Sync with defter now.",
    sync_heading: "commonmeta",
    sync_intro: "Every day, commonmeta fills in what the items in your library with a DOI \
                 lack — authors, publication date, journal, license and more — from its \
                 store of Crossref and DataCite records, and gives an item the type its \
                 work calls for. A field you filled in is kept. An item whose type changes \
                 is first copied to the trash, and Zotero picks the changes up on its next \
                 sync. At most 1,000 items change a day; the rest follow.",
    sync_enabled: "Keep my library up to date",
    sync_pdf: "Attach the PDFs commonmeta knows to items that have none",
    sync_publications: "Add the works of my ORCID record to My Publications",
    sync_needs_orcid: "Needs an ORCID iD on your account.",
    sync_deduplicate: "Merge items that share a DOI, moving the others to the trash",
    sync_overwrite: "Replace journal, date, authors, license and DOI with commonmeta's",
    sync_overwrite_hint: "Changes what you entered. Preview first: the changes download as \
                          JSON, each with its old and new value.",
    sync_log: "Download the changes as JSON",
    sync_preview: "Preview changes",
    sync_now: "Sync now",
    sync_running: "A sync of your library is running.",
    sync_busy: "Another sync is running; try again in a few minutes.",
    sync_never: "Your library has not been synced yet.",
    sync_last: "Last sync:",
    sync_last_preview: "Last preview:",
    sync_details: "Changes",
    sync_more: "more not shown",
    sync_ok: "done",
    sync_partial: "done, with problems",
    sync_failed: "failed",
    sync_aborted: "stopped, as sync was turned off; changes listed below were made before",
    sync_off: "off",
    sync_on: "on",
    sync_on_pdf: "on, with PDFs",
    sync_opted_in: "users keep their library up to date",
    sync_newest: "newest sync",
    sync_last_failed: "last sync failed",
    sign_in: "Sign in",
    api_key: "API key",
    key_holders: "This server's library status and settings are shown to holders of one of its \
                  API keys.",
    needs_signing_in: "This server's library status and settings need signing in.",
    sign_in_with: "Sign in with",
    sign_in_with_end: "",
    approve_with_end: "to approve",
    from_another_site: "The sign-in was sent from another site.",
    not_a_key: "That is not an API key of this library.",
    sign_in_failed: "Signing in did not work. Please try again.",
    no_orcid: "This account has no ORCID iD, which signing in here needs.",
    not_allowed: "This account is not allowed into this library.",
    ask_admin_email: "To use defter, ask to be added — write to",
    ask_admin: "To use defter, ask the admins of this server to add you, or your \
                institution's IT.",
    connect_account: "Connect your zotero.org account",
    connect_why: "Your user ID here is your zotero.org user ID, so that your Zotero can sync \
                  the same library with zotero.org and with defter.",
    connect_how: "Create a key on zotero.org; read-only access is enough. Paste it here:",
    connect_key_page: "zotero.org → Settings → Security → Create new private key",
    connect_kept: "defter asks zotero.org whose the key is and keeps only your user ID and \
                   user name: the key is not stored. You can delete it on zotero.org afterwards.",
    zotero_key: "zotero.org API key",
    connect: "Connect",
    zotero_key_rejected: "zotero.org did not accept this key.",
    zotero_unreachable: "zotero.org could not be reached. Please try again later.",
    zotero_id_taken: "This zotero.org account belongs to another user here. If it is yours, \
                      please ask an admin of this server.",
    account_expired: "This sign-in has expired. Please sign in again.",
    signing_out: "Signing out",
    signed_out_here: "You are signed out here. If nothing happens,",
    continue_signing_out: "continue signing out",
    authorize_zotero: "Authorize Zotero?",
    authorized: "Authorized",
    login_expired: "Login expired",
    no_login_request: "No login request",
    not_authorized: "Not authorized",
    pending_signed_in: "A Zotero client asked to sync with this library. Approve only if you \
                        just started the login yourself.",
    pending_sign_in: "A Zotero client asked to sync with this library. Sign in to approve, and \
                      only if you just started the login yourself.",
    pending_key: "A Zotero client asked to sync with this library. Approve with an API key that \
                  may write to it, and only if you just started the login yourself.",
    return_to_zotero: "You can close this page and return to Zotero.",
    expired_message: "This login request is unknown or has expired. Start the login in Zotero \
                      again.",
    missing_message: "Open this page from Zotero’s Settings → Sync → Log In.",
    approve: "Approve",
    approval_from_another_site: "The approval was sent from another site.",
    not_allowed_to_approve: "You are not allowed to approve logins to this library.",
    signed_in_as: "Signed in as",
    storage_used: "Storage used",
    of: "of",
    no_limit: "no limit",
    over_quota: "Your storage is full: new attachment files are refused until you delete some or an admin raises your quota.",
    devices: "Devices",
    devices_intro: "The keys your Zotero logins got. Revoke one to sign that device out.",
    no_devices: "No devices yet: log in from Zotero to connect one.",
    revoke: "Revoke",
    added: "added",
    last_used: "last used",
    never_used: "not used yet",
    admin: "Admin",
    invites: "Invitations",
    invites_intro: "Someone with an invited ORCID iD can sign in and gets a library of their own.",
    no_invites: "Nobody is invited.",
    invites_off: "Invitations do not apply: the sign-in provider decides who can sign in and get a library of their own, by their groups or roles. Someone who loses them is disabled when they next sign in, and enabled again when they sign in with them again, unless an admin disabled them. The owner and the admins named on the server need none.",
    access_claim: "Claim",
    access_users: "Users",
    access_admins: "Admins",
    disabled_by_provider: "disabled at sign-in: no longer in the group or role",
    orcid_id: "ORCID iD",
    note: "Note",
    invite: "Invite",
    uninvite: "Withdraw",
    invite_used: "now user",
    not_an_orcid: "That is not an ORCID iD.",
    already_a_user: "That ORCID iD is a user already.",
    not_a_quota: "A quota is a number of MB, or nothing for the default.",
    users: "Users",
    quota_mb: "Quota (MB)",
    default_quota_is: "empty for the default:",
    empty_for_no_limit: "empty for no limit",
    save: "Save",
    disable: "Disable",
    enable: "Enable",
    disabled: "disabled",
    owner: "owner",
    you: "you",
    devices_count: "devices",
    groups: "Groups",
    groups_intro: "Group libraries are shared by their members, who sync them in Zotero beside their own.",
    no_groups: "You are in no group.",
    group_name: "Name",
    create_group: "Create group",
    group_description: "Description",
    library_editing: "Who may edit the library",
    file_editing: "Who may add and change files",
    editing_members: "all members",
    editing_admins: "only admins",
    editing_none: "nobody",
    members: "Members",
    add_member: "Add",
    add_member_intro: "A user of this server, by their ORCID iD.",
    role: "Role",
    role_owner: "owner",
    role_admin: "admin",
    role_member: "member",
    make_admin: "Make admin",
    make_member: "Make member",
    remove: "Remove",
    leave_group: "Leave group",
    delete_group: "Delete group",
    delete_group_note: "Members' Zotero clients are told the group is gone. Its library is kept, and backed up.",
    not_a_user_yet: "That ORCID iD is no user of this server: an admin can invite them.",
    your_role: "Your role:",
    back_to_library: "Back to your library",
    sign_in_to_approve: "Sign in to approve logins to this library.",
    key_only_reads: "This key may only read; approve with one that may write.",
};

const PAGES_DE: Pages = Pages {
    library: "Bibliothek",
    library_version: "Bibliotheksversion",
    user: "Nutzer",
    items: "Einträge",
    attachments: "Anhänge",
    notes: "Notizen",
    collections: "Sammlungen",
    tags: "Tags",
    in_trash: "Im Papierkorb",
    files: "Dateien",
    stored: "Gespeichert",
    attachment_storage: "Dateispeicher",
    backups: "Sicherungen",
    backup_last: "Letzte Sicherung:",
    backup_never: "Seit dem Start des Servers lief noch keine Sicherung.",
    backup_off: "Geplante Sicherungen sind aus.",
    backup_failed: "Die letzte Sicherung ist fehlgeschlagen:",
    backup_warning: "Mit einer Warnung:",
    signed_downloads: "Clients laden Dateien über vorsignierte URLs direkt aus dem Bucket.",
    streamed_downloads: "Downloads laufen über diesen Server.",
    files_up_to: "Dateien bis",
    are_accepted: "werden angenommen.",
    public_profile: "Öffentliches Profil",
    profile_hidden: "Verborgen: Die Adresse antwortet mit „nicht gefunden“.",
    profile_visible: "Für alle sichtbar.",
    it_lists: "Es listet",
    all_of_my_publications: ": alles aus „Meine Publikationen“ in Zotero.",
    show_profile: "Profil anzeigen",
    hide_profile: "Profil verbergen",
    connect_zotero: "Zotero verbinden",
    connect_intro: "defter arbeitet neben zotero.org: Zotero synchronisiert weiter mit \
                    zotero.org und Zotero Storage, und das Plugin defter for Zotero \
                    synchronisiert deine Bibliothek zusätzlich mit diesem Server. Erfordert \
                    Zotero 10.",
    connect_download: "Lade",
    connect_install: " herunter und installiere es in Zotero unter Werkzeuge → Plugins → \
                      Zahnradmenü → Plugin aus Datei installieren…",
    connect_server: "Öffne in Zotero Einstellungen → defter und gib diesen Server ein:",
    connect_login: "Klicke auf Anmelden, bestätige die Anmeldung auf diesem Server und dann auf \
                    Jetzt mit defter synchronisieren.",
    sync_heading: "commonmeta",
    sync_intro: "Jeden Tag ergänzt commonmeta, was den Einträgen deiner Bibliothek mit DOI \
                 fehlt – Autoren, Erscheinungsdatum, Zeitschrift, Lizenz und mehr – aus \
                 seinem Bestand an Crossref- und DataCite-Datensätzen, und gibt einem \
                 Eintrag den Typ, den sein Werk verlangt. Ein Feld, das du ausgefüllt hast, \
                 bleibt. Ein Eintrag, dessen Typ sich ändert, wird vorher in den Papierkorb \
                 kopiert, und Zotero übernimmt die Änderungen bei der nächsten \
                 Synchronisierung. Höchstens 1.000 Einträge ändern sich pro Tag; der Rest \
                 folgt.",
    sync_enabled: "Meine Bibliothek aktuell halten",
    sync_pdf: "Einträgen ohne PDF die PDFs anhängen, die commonmeta kennt",
    sync_publications: "Die Werke meines ORCID-Datensatzes zu „Meine Publikationen“ hinzufügen",
    sync_needs_orcid: "Dazu braucht dein Konto eine ORCID iD.",
    sync_deduplicate: "Einträge mit derselben DOI zusammenführen und die übrigen in den \
                       Papierkorb legen",
    sync_overwrite: "Zeitschrift, Datum, Autoren, Lizenz und DOI durch die von commonmeta \
                     ersetzen",
    sync_overwrite_hint: "Ändert, was du eingetragen hast. Sieh dir vorher die Vorschau an: \
                          die Änderungen lassen sich als JSON herunterladen, jede mit altem \
                          und neuem Wert.",
    sync_log: "Änderungen als JSON herunterladen",
    sync_preview: "Änderungen ansehen",
    sync_now: "Jetzt synchronisieren",
    sync_running: "Deine Bibliothek wird gerade synchronisiert.",
    sync_busy: "Eine andere Synchronisierung läuft; versuch es in ein paar Minuten noch einmal.",
    sync_never: "Deine Bibliothek wurde noch nicht synchronisiert.",
    sync_last: "Letzte Synchronisierung:",
    sync_last_preview: "Letzte Vorschau:",
    sync_details: "Änderungen",
    sync_more: "weitere nicht angezeigt",
    sync_ok: "fertig",
    sync_partial: "fertig, mit Problemen",
    sync_failed: "fehlgeschlagen",
    sync_aborted: "abgebrochen, da die Synchronisierung ausgeschaltet wurde; die unten \
                   aufgeführten Änderungen wurden vorher gemacht",
    sync_off: "aus",
    sync_on: "an",
    sync_on_pdf: "an, mit PDFs",
    sync_opted_in: "Nutzern halten ihre Bibliothek aktuell",
    sync_newest: "neueste Synchronisierung",
    sync_last_failed: "letzte Synchronisierung fehlgeschlagen",
    sign_in: "Anmelden",
    api_key: "API-Schlüssel",
    key_holders: "Status und Einstellungen dieser Bibliothek sehen nur Inhaber eines ihrer \
                  API-Schlüssel.",
    needs_signing_in: "Für Status und Einstellungen dieser Bibliothek ist eine Anmeldung nötig.",
    sign_in_with: "Mit",
    sign_in_with_end: "anmelden",
    approve_with_end: "anmelden und bestätigen",
    from_another_site: "Die Anmeldung kam von einer anderen Website.",
    not_a_key: "Das ist kein API-Schlüssel dieser Bibliothek.",
    sign_in_failed: "Die Anmeldung hat nicht geklappt. Bitte versuche es noch einmal.",
    no_orcid: "Dieses Konto hat keine ORCID iD, die für die Anmeldung hier nötig ist.",
    not_allowed: "Dieses Konto hat keinen Zugang zu dieser Bibliothek.",
    ask_admin_email: "Um defter zu nutzen, bitte darum, freigeschaltet zu werden – schreib an",
    ask_admin: "Um defter zu nutzen, bitte die Admins dieses Servers oder die IT deiner \
                Einrichtung, dich freizuschalten.",
    connect_account: "Verbinde dein zotero.org-Konto",
    connect_why: "Deine Nutzer-ID hier ist deine zotero.org-Nutzer-ID, damit dein Zotero \
                  dieselbe Bibliothek mit zotero.org und mit defter synchronisieren kann.",
    connect_how: "Erstelle einen Schlüssel auf zotero.org; Lesezugriff genügt. Füge ihn hier ein:",
    connect_key_page: "zotero.org → Settings → Security → Create new private key",
    connect_kept: "defter fragt zotero.org, wem der Schlüssel gehört, und behält nur deine \
                   Nutzer-ID und deinen Nutzernamen: Der Schlüssel wird nicht gespeichert. Du \
                   kannst ihn danach auf zotero.org löschen.",
    zotero_key: "zotero.org-API-Schlüssel",
    connect: "Verbinden",
    zotero_key_rejected: "zotero.org hat diesen Schlüssel nicht angenommen.",
    zotero_unreachable: "zotero.org war nicht erreichbar. Bitte versuche es später noch einmal.",
    zotero_id_taken: "Dieses zotero.org-Konto gehört hier schon jemand anderem. Wenn es \
                      deines ist, wende dich bitte an eine Verwaltungsperson dieses Servers.",
    account_expired: "Diese Anmeldung ist abgelaufen. Bitte melde dich noch einmal an.",
    signing_out: "Abmelden",
    signed_out_here: "Du bist hier abgemeldet. Falls nichts passiert,",
    continue_signing_out: "Abmeldung fortsetzen",
    authorize_zotero: "Zotero zulassen?",
    authorized: "Zugelassen",
    login_expired: "Anmeldung abgelaufen",
    no_login_request: "Keine Anmeldeanfrage",
    not_authorized: "Nicht zugelassen",
    pending_signed_in: "Ein Zotero-Client möchte mit dieser Bibliothek synchronisieren. Bestätige \
                        nur, wenn du die Anmeldung gerade selbst gestartet hast.",
    pending_sign_in: "Ein Zotero-Client möchte mit dieser Bibliothek synchronisieren. Melde dich \
                      an, um zu bestätigen, und nur, wenn du die Anmeldung gerade selbst \
                      gestartet hast.",
    pending_key: "Ein Zotero-Client möchte mit dieser Bibliothek synchronisieren. Bestätige mit \
                  einem API-Schlüssel mit Schreibrecht, und nur, wenn du die Anmeldung gerade \
                  selbst gestartet hast.",
    return_to_zotero: "Du kannst diese Seite schließen und zu Zotero zurückkehren.",
    expired_message: "Diese Anmeldeanfrage ist unbekannt oder abgelaufen. Starte die Anmeldung \
                      in Zotero noch einmal.",
    missing_message: "Öffne diese Seite aus Zotero über Einstellungen → Sync → Anmelden.",
    approve: "Bestätigen",
    approval_from_another_site: "Die Bestätigung kam von einer anderen Website.",
    not_allowed_to_approve: "Du darfst keine Anmeldungen bei dieser Bibliothek bestätigen.",
    signed_in_as: "Angemeldet als",
    storage_used: "Belegter Speicher",
    of: "von",
    no_limit: "unbegrenzt",
    over_quota: "Dein Speicher ist voll: Neue Anhänge werden abgelehnt, bis du welche löschst oder eine Verwaltungsperson dein Kontingent erhöht.",
    devices: "Geräte",
    devices_intro: "Die Schlüssel, die deine Zotero-Anmeldungen erhalten haben. Widerrufe einen, um das Gerät abzumelden.",
    no_devices: "Noch keine Geräte: Melde dich in Zotero an, um eines zu verbinden.",
    revoke: "Widerrufen",
    added: "hinzugefügt",
    last_used: "zuletzt benutzt",
    never_used: "noch nicht benutzt",
    admin: "Verwaltung",
    invites: "Einladungen",
    invites_intro: "Wer eine eingeladene ORCID iD hat, kann sich anmelden und erhält eine eigene Bibliothek.",
    no_invites: "Niemand ist eingeladen.",
    invites_off: "Einladungen gelten nicht: Der Anmeldedienst entscheidet anhand der Gruppen oder Rollen, wer sich anmelden kann und eine eigene Bibliothek erhält. Wer sie verliert, wird bei der nächsten Anmeldung gesperrt und wieder entsperrt, wenn er sich mit ihnen wieder anmeldet, außer die Verwaltung hat ihn gesperrt. Der Inhaber und die auf dem Server genannten Admins brauchen keine.",
    access_claim: "Claim",
    access_users: "Benutzer",
    access_admins: "Verwaltung",
    disabled_by_provider: "bei der Anmeldung gesperrt: nicht mehr in der Gruppe oder Rolle",
    orcid_id: "ORCID iD",
    note: "Notiz",
    invite: "Einladen",
    uninvite: "Zurückziehen",
    invite_used: "jetzt Benutzer",
    not_an_orcid: "Das ist keine ORCID iD.",
    already_a_user: "Diese ORCID iD gehört schon einem Benutzer.",
    not_a_quota: "Ein Kontingent ist eine Zahl in MB, oder leer für den Standard.",
    users: "Benutzer",
    quota_mb: "Kontingent (MB)",
    default_quota_is: "leer für den Standard:",
    empty_for_no_limit: "leer für unbegrenzt",
    save: "Speichern",
    disable: "Sperren",
    enable: "Entsperren",
    disabled: "gesperrt",
    owner: "Inhaber",
    you: "du",
    devices_count: "Geräte",
    groups: "Gruppen",
    groups_intro: "Gruppenbibliotheken teilen sich ihre Mitglieder, die sie in Zotero neben ihrer eigenen synchronisieren.",
    no_groups: "Du bist in keiner Gruppe.",
    group_name: "Name",
    create_group: "Gruppe anlegen",
    group_description: "Beschreibung",
    library_editing: "Wer die Bibliothek bearbeiten darf",
    file_editing: "Wer Dateien hinzufügen und ändern darf",
    editing_members: "alle Mitglieder",
    editing_admins: "nur Admins",
    editing_none: "niemand",
    members: "Mitglieder",
    add_member: "Hinzufügen",
    add_member_intro: "Ein Benutzer dieses Servers, über seine ORCID iD.",
    role: "Rolle",
    role_owner: "Inhaber",
    role_admin: "Admin",
    role_member: "Mitglied",
    make_admin: "Zum Admin machen",
    make_member: "Zum Mitglied machen",
    remove: "Entfernen",
    leave_group: "Gruppe verlassen",
    delete_group: "Gruppe löschen",
    delete_group_note: "Die Zotero-Clients der Mitglieder erfahren, dass die Gruppe weg ist. Ihre Bibliothek bleibt erhalten und gesichert.",
    not_a_user_yet: "Diese ORCID iD gehört keinem Benutzer dieses Servers: Eine Verwaltungsperson kann sie einladen.",
    your_role: "Deine Rolle:",
    back_to_library: "Zurück zu deiner Bibliothek",
    sign_in_to_approve: "Melde dich an, um Anmeldungen bei dieser Bibliothek zu bestätigen.",
    key_only_reads: "Dieser Schlüssel darf nur lesen; bestätige mit einem mit Schreibrecht.",
};

/// The words in `templates/base.html`.
pub struct LayoutText {
    pub lang: &'static str,
    pub toggle_dark: &'static str,
    pub sign_out: &'static str,
    pub language: &'static str,
    pub apply: &'static str,
    pub tagline: &'static str,
    pub built_with: &'static str,
    pub by: &'static str,
    pub software: &'static str,
    pub mit_license: &'static str,
}

pub const LAYOUT_EN: LayoutText = LayoutText {
    lang: "en",
    toggle_dark: "Toggle dark mode",
    sign_out: "Sign out",
    language: "Language",
    apply: "Apply",
    tagline: "Self-hosted Zotero sync and file storage",
    built_with: "Built with",
    by: "by",
    software: "software provided under an",
    mit_license: "MIT license",
};

const LAYOUT_DE: LayoutText = LayoutText {
    lang: "de",
    toggle_dark: "Dunkelmodus umschalten",
    sign_out: "Abmelden",
    language: "Sprache",
    apply: "Anwenden",
    tagline: "Selbst gehostete Zotero-Synchronisierung und Dateiablage",
    built_with: "Erstellt mit",
    by: "von",
    software: "Software bereitgestellt unter einer",
    mit_license: "MIT-Lizenz",
};

const MONTHS_EN: [&str; 12] = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
];

const MONTHS_DE: [&str; 12] = [
    "Januar",
    "Februar",
    "März",
    "April",
    "Mai",
    "Juni",
    "Juli",
    "August",
    "September",
    "Oktober",
    "November",
    "Dezember",
];

/// German names of Zotero's item types. English ones are derived from the type.
const ITEM_TYPES_DE: &[(&str, &str)] = &[
    ("artwork", "Kunstwerk"),
    ("audioRecording", "Tonaufnahme"),
    ("bill", "Gesetzentwurf"),
    ("blogPost", "Blogbeitrag"),
    ("book", "Buch"),
    ("bookSection", "Buchkapitel"),
    ("case", "Gerichtsentscheidung"),
    ("computerProgram", "Software"),
    ("conferencePaper", "Konferenzbeitrag"),
    ("dataset", "Datensatz"),
    ("dictionaryEntry", "Wörterbucheintrag"),
    ("document", "Dokument"),
    ("email", "E-Mail"),
    ("encyclopediaArticle", "Lexikonartikel"),
    ("film", "Film"),
    ("forumPost", "Forumsbeitrag"),
    ("hearing", "Anhörung"),
    ("instantMessage", "Sofortnachricht"),
    ("interview", "Interview"),
    ("journalArticle", "Zeitschriftenartikel"),
    ("letter", "Brief"),
    ("magazineArticle", "Magazinartikel"),
    ("manuscript", "Manuskript"),
    ("map", "Karte"),
    ("newspaperArticle", "Zeitungsartikel"),
    ("patent", "Patent"),
    ("podcast", "Podcast"),
    ("preprint", "Preprint"),
    ("presentation", "Präsentation"),
    ("radioBroadcast", "Radiosendung"),
    ("report", "Bericht"),
    ("standard", "Norm"),
    ("statute", "Gesetz"),
    ("thesis", "Abschlussarbeit"),
    ("tvBroadcast", "Fernsehsendung"),
    ("videoRecording", "Videoaufnahme"),
    ("webpage", "Webseite"),
];

/// The languages of works most often seen, by primary subtag.
const LANGUAGES: &[(&str, &str, &str)] = &[
    ("ar", "Arabic", "Arabisch"),
    ("cs", "Czech", "Tschechisch"),
    ("da", "Danish", "Dänisch"),
    ("de", "German", "Deutsch"),
    ("el", "Greek", "Griechisch"),
    ("en", "English", "Englisch"),
    ("es", "Spanish", "Spanisch"),
    ("fi", "Finnish", "Finnisch"),
    ("fr", "French", "Französisch"),
    ("he", "Hebrew", "Hebräisch"),
    ("hu", "Hungarian", "Ungarisch"),
    ("it", "Italian", "Italienisch"),
    ("ja", "Japanese", "Japanisch"),
    ("ko", "Korean", "Koreanisch"),
    ("nb", "Norwegian", "Norwegisch"),
    ("nl", "Dutch", "Niederländisch"),
    ("no", "Norwegian", "Norwegisch"),
    ("pl", "Polish", "Polnisch"),
    ("pt", "Portuguese", "Portugiesisch"),
    ("ru", "Russian", "Russisch"),
    ("sv", "Swedish", "Schwedisch"),
    ("tr", "Turkish", "Türkisch"),
    ("zh", "Chinese", "Chinesisch"),
];

impl Lang {
    /// What the language switcher offers.
    pub const ALL: [Lang; 2] = [Lang::En, Lang::De];

    pub fn parse(code: &str) -> Option<Lang> {
        match code.to_ascii_lowercase().as_str() {
            "en" => Some(Lang::En),
            "de" => Some(Lang::De),
            _ => None,
        }
    }

    /// The first language in an `Accept-Language` header that is available,
    /// else English. Browsers list their languages by preference.
    pub fn from_accept_language(header: &str) -> Lang {
        header
            .split(',')
            .filter_map(|tag| {
                let tag = tag.split(';').next()?.trim();
                Lang::parse(tag.split('-').next()?)
            })
            .next()
            .unwrap_or(Lang::En)
    }

    pub fn code(&self) -> &'static str {
        match self {
            Lang::En => "en",
            Lang::De => "de",
        }
    }

    /// The language's name, in that language.
    pub fn name(&self) -> &'static str {
        match self {
            Lang::En => "English",
            Lang::De => "Deutsch",
        }
    }

    /// The locale formatted citations are written in.
    pub fn citation_locale(self) -> &'static str {
        match self {
            Lang::En => "en-US",
            Lang::De => "de-DE",
        }
    }

    pub fn text(self) -> &'static Text {
        match self {
            Lang::En => &EN,
            Lang::De => &DE,
        }
    }

    pub fn pages(self) -> &'static Pages {
        match self {
            Lang::En => &PAGES_EN,
            Lang::De => &PAGES_DE,
        }
    }

    /// A number with a decimal point, as written in this language.
    pub fn decimal(self, number: &str) -> String {
        match self {
            Lang::En => number.to_string(),
            Lang::De => number.replace('.', ","),
        }
    }

    pub fn layout(self) -> &'static LayoutText {
        match self {
            Lang::En => &LAYOUT_EN,
            Lang::De => &LAYOUT_DE,
        }
    }

    /// `1043` → "1,043" or "1.043".
    pub fn count(&self, n: usize) -> String {
        let separator = match self {
            Lang::En => ',',
            Lang::De => '.',
        };
        let digits = n.to_string();
        let mut out = String::with_capacity(digits.len() + digits.len() / 3);
        for (i, digit) in digits.chars().enumerate() {
            if i > 0 && (digits.len() - i).is_multiple_of(3) {
                out.push(separator);
            }
            out.push(digit);
        }
        out
    }

    /// "1 work", "1,043 works".
    pub fn works(self, n: usize) -> String {
        let noun = match (self, n) {
            (Lang::En, 1) => "work",
            (Lang::En, _) => "works",
            (_, 1) => "Werk",
            (_, _) => "Werke",
        };
        format!("{} {noun}", self.count(n))
    }

    /// What a sync did, in words: "1,204 items, 310 with a DOI: 12 updated,
    /// 2 PDFs attached". Only what happened is named; a preview says what
    /// would happen.
    pub fn sync_counts(self, s: &commonmeta::zotero::SyncSummary, preview: bool) -> String {
        // commonmeta counts an item left for the next sync as deferred only.
        let with_doi = self.count(s.with_doi + s.deferred);
        let items = self.count(s.items);
        let head = match (self, s.items) {
            (Lang::En, 1) => format!("{items} item, {with_doi} with a DOI"),
            (Lang::En, _) => format!("{items} items, {with_doi} with a DOI"),
            (Lang::De, 1) => format!("{items} Eintrag, {with_doi} mit DOI"),
            (Lang::De, _) => format!("{items} Einträge, {with_doi} mit DOI"),
        };
        // (count, English, English preview, German, German preview)
        let counts = [
            (
                s.updated,
                "updated",
                "to update",
                "aktualisiert",
                "zu aktualisieren",
            ),
            (
                s.created,
                "added to My Publications",
                "to add to My Publications",
                "zu „Meine Publikationen“ hinzugefügt",
                "zu „Meine Publikationen“ hinzuzufügen",
            ),
            (
                s.published,
                "put into My Publications",
                "to put into My Publications",
                "in „Meine Publikationen“ aufgenommen",
                "in „Meine Publikationen“ aufzunehmen",
            ),
            (
                s.orcid_concepts,
                "left out of My Publications (concept DOI without a PDF)",
                "to leave out of My Publications (concept DOI without a PDF)",
                "nicht in „Meine Publikationen“ (Konzept-DOI ohne PDF)",
                "nicht in „Meine Publikationen“ aufzunehmen (Konzept-DOI ohne PDF)",
            ),
            (
                s.pdfs,
                "PDFs attached",
                "PDFs to attach",
                "PDFs angehängt",
                "PDFs anzuhängen",
            ),
            (
                s.duplicates + s.versions,
                "duplicates merged",
                "duplicates to merge",
                "Dubletten zusammengeführt",
                "Dubletten zusammenzuführen",
            ),
            (
                s.conflicts,
                "changed meanwhile, left for the next sync",
                "changed meanwhile",
                "inzwischen geändert, für die nächste Synchronisierung gelassen",
                "inzwischen geändert",
            ),
            (
                s.failed,
                "failed",
                "failed",
                "fehlgeschlagen",
                "fehlgeschlagen",
            ),
            (
                s.deferred,
                "left for the next sync",
                "left for the next sync",
                "für die nächste Synchronisierung gelassen",
                "für die nächste Synchronisierung gelassen",
            ),
        ];
        let done: Vec<String> = counts
            .iter()
            .filter(|c| c.0 > 0)
            .map(|&(n, en, en_preview, de, de_preview)| {
                let words = match (self, preview) {
                    (Lang::En, false) => en,
                    (Lang::En, true) => en_preview,
                    (Lang::De, false) => de,
                    (Lang::De, true) => de_preview,
                };
                format!("{} {words}", self.count(n))
            })
            .collect();
        if done.is_empty() {
            let nothing = match self {
                Lang::En => "nothing to change",
                Lang::De => "nichts zu ändern",
            };
            return format!("{head}: {nothing}");
        }
        format!("{head}: {}", done.join(", "))
    }

    /// "page 1 of 105".
    pub fn page_of(self, page: usize, pages: usize) -> String {
        let (page, pages) = (self.count(page), self.count(pages));
        match self {
            Lang::En => format!("page {page} of {pages}"),
            Lang::De => format!("Seite {page} von {pages}"),
        }
    }

    /// A partial date for people: `2015` → "2015", `2015-08` → "August 2015",
    /// `2021-08-01` → "August 1, 2021" or "1. August 2021". Anything else, such
    /// as Zotero's free-form dates, stays as it is.
    pub fn date(self, date: &str) -> String {
        let parts: Vec<&str> = date.trim().split('-').collect();
        let months = match self {
            Lang::En => &MONTHS_EN,
            Lang::De => &MONTHS_DE,
        };
        let month = parts
            .get(1)
            .and_then(|m| m.parse::<usize>().ok())
            .and_then(|m| months.get(m.wrapping_sub(1)));
        let day = parts.get(2).and_then(|d| d.parse::<u32>().ok());
        match (self, parts[0], month, day) {
            (Lang::En, year, Some(month), Some(day)) => format!("{month} {day}, {year}"),
            (_, year, Some(month), Some(day)) => format!("{day}. {month} {year}"),
            (_, year, Some(month), None) => format!("{month} {year}"),
            (_, year, _, _) => year.to_string(),
        }
    }

    pub fn date_range(self, start: &str, end: &str) -> String {
        let text = self.text();
        match (start.trim().is_empty(), end.trim().is_empty()) {
            (false, false) => format!("{} – {}", self.date(start), self.date(end)),
            (false, true) => format!("{} {}", text.started, self.date(start)),
            (true, false) => format!("{} {}", text.ended, self.date(end)),
            (true, true) => String::new(),
        }
    }

    /// `journalArticle` → "Journal article" or "Zeitschriftenartikel".
    pub fn item_type(self, item_type: &str) -> String {
        if self != Lang::En
            && let Some((_, label)) = ITEM_TYPES_DE.iter().find(|(t, _)| *t == item_type)
        {
            return label.to_string();
        }
        let mut label = String::new();
        for (i, c) in item_type.chars().enumerate() {
            if i == 0 {
                label.extend(c.to_uppercase());
            } else if c.is_uppercase() {
                label.push(' ');
                label.extend(c.to_lowercase());
            } else {
                label.push(c);
            }
        }
        label
    }

    /// The name of a work's language: `en-US` → "English". Zotero's field is
    /// free text, so anything else stays as it is.
    pub fn language(self, language: &str) -> String {
        let language = language.trim();
        let primary = language
            .split('-')
            .next()
            .unwrap_or("")
            .to_ascii_lowercase();
        match LANGUAGES.iter().find(|(code, _, _)| *code == primary) {
            Some((_, en, _)) if self == Lang::En => en.to_string(),
            Some((_, _, de)) => de.to_string(),
            None => language.to_string(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn picks_a_language_from_the_browser() {
        let accept = Lang::from_accept_language;
        assert_eq!(accept("de-DE,de;q=0.9,en;q=0.8"), Lang::De);
        assert_eq!(accept("de-AT,de;q=0.9"), Lang::De);
        assert_eq!(accept("fr-FR,fr;q=0.9,de;q=0.8,en;q=0.7"), Lang::De);
        assert_eq!(accept("en-GB,de;q=0.5"), Lang::En);
        assert_eq!(accept("fr"), Lang::En);
        assert_eq!(accept(""), Lang::En);
    }

    #[test]
    fn formats_dates_and_ranges() {
        assert_eq!(Lang::En.date("2015"), "2015");
        assert_eq!(Lang::En.date("2015-08"), "August 2015");
        assert_eq!(Lang::En.date("2021-08-01"), "August 1, 2021");
        assert_eq!(Lang::De.date("2021-08-01"), "1. August 2021");
        assert_eq!(Lang::De.date("2015-03"), "März 2015");
        assert_eq!(Lang::De.date("2021-01-05"), "5. Januar 2021");
        assert_eq!(Lang::En.date("May 2021"), "May 2021");
        assert_eq!(
            Lang::En.date_range("2021-08-01", ""),
            "Started August 1, 2021"
        );
        assert_eq!(
            Lang::De.date_range("2021-08-01", ""),
            "Beginn 1. August 2021"
        );
        assert_eq!(
            Lang::En.date_range("2015-08", "2021-07-31"),
            "August 2015 – July 31, 2021"
        );
        assert_eq!(Lang::En.date_range("", ""), "");
    }

    /// A work the ORCID record lists only by a concept DOI without a PDF is
    /// named as left out of My Publications, as done and as a preview.
    #[test]
    fn a_left_out_concept_is_counted() {
        let s = commonmeta::zotero::SyncSummary {
            items: 3,
            with_doi: 3,
            orcid_concepts: 1,
            ..Default::default()
        };
        assert_eq!(
            Lang::En.sync_counts(&s, false),
            "3 items, 3 with a DOI: 1 left out of My Publications (concept DOI without a PDF)"
        );
        assert!(
            Lang::En
                .sync_counts(&s, true)
                .ends_with("1 to leave out of My Publications (concept DOI without a PDF)")
        );
        assert!(
            Lang::De
                .sync_counts(&s, false)
                .ends_with("1 nicht in „Meine Publikationen“ (Konzept-DOI ohne PDF)")
        );
    }

    #[test]
    fn counts_in_the_page_language() {
        assert_eq!(Lang::En.count(1043), "1,043");
        assert_eq!(Lang::De.count(1043), "1.043");
        assert_eq!(Lang::En.count(999), "999");
        assert_eq!(Lang::En.works(1), "1 work");
        assert_eq!(Lang::De.works(1043), "1.043 Werke");
        assert_eq!(Lang::De.page_of(1, 105), "Seite 1 von 105");
    }

    #[test]
    fn names_types_and_languages() {
        assert_eq!(Lang::En.item_type("blogPost"), "Blog post");
        assert_eq!(Lang::De.item_type("blogPost"), "Blogbeitrag");
        assert_eq!(Lang::De.item_type("unknownType"), "Unknown type");
        assert_eq!(Lang::En.language("en-US"), "English");
        assert_eq!(Lang::De.language("en"), "Englisch");
        assert_eq!(Lang::En.language("Klingon"), "Klingon");
    }
}