@stevenkellner/team-conduct-api 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/index.ts +1 -4
  2. package/lib/index.d.ts +1 -4
  3. package/lib/index.js +1 -4
  4. package/lib/src/firebaseFunctionsContext.d.ts +1 -14
  5. package/lib/src/firebaseFunctionsContext.js +19 -36
  6. package/lib/src/functions/fine/add.js +3 -37
  7. package/lib/src/functions/fine/delete.js +3 -37
  8. package/lib/src/functions/fine/update.js +4 -38
  9. package/lib/src/functions/index.d.ts +18 -0
  10. package/lib/src/functions/index.js +34 -0
  11. package/lib/src/index.d.ts +8 -0
  12. package/lib/src/index.js +24 -0
  13. package/lib/src/locales/de.json +65 -0
  14. package/lib/src/locales/en.json +65 -0
  15. package/lib/src/types/FineAmount.d.ts +2 -1
  16. package/lib/src/types/FineAmount.js +7 -42
  17. package/lib/src/types/FineTemplateRepetition.d.ts +2 -0
  18. package/lib/src/types/FineTemplateRepetition.js +8 -0
  19. package/lib/src/types/Localization.d.ts +70 -0
  20. package/lib/src/types/Localization.js +123 -0
  21. package/lib/src/types/PayedState.d.ts +1 -0
  22. package/lib/src/types/PayedState.js +5 -0
  23. package/lib/src/types/UserRole.d.ts +1 -0
  24. package/lib/src/types/UserRole.js +11 -0
  25. package/lib/src/types/index.d.ts +1 -0
  26. package/lib/src/types/index.js +1 -0
  27. package/lib/test/localization-utils.d.ts +12 -0
  28. package/lib/test/localization-utils.js +68 -0
  29. package/lib/test/localization.de.test.d.ts +1 -0
  30. package/lib/test/localization.de.test.js +162 -0
  31. package/lib/test/localization.en.test.d.ts +1 -0
  32. package/lib/test/localization.en.test.js +158 -0
  33. package/lib/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +6 -1
  35. package/src/firebaseFunctionsContext.ts +7 -18
  36. package/src/functions/fine/add.ts +5 -5
  37. package/src/functions/fine/delete.ts +4 -5
  38. package/src/functions/fine/update.ts +5 -6
  39. package/src/functions/index.ts +19 -0
  40. package/src/index.ts +8 -0
  41. package/src/locales/de.json +63 -28
  42. package/src/locales/en.json +49 -14
  43. package/src/types/FineAmount.ts +7 -9
  44. package/src/types/FineTemplateRepetition.ts +9 -0
  45. package/src/types/Localization.ts +94 -0
  46. package/src/types/PayedState.ts +5 -0
  47. package/src/types/UserRole.ts +11 -0
  48. package/src/types/index.ts +1 -0
@@ -0,0 +1,94 @@
1
+ import * as i18n from 'i18n';
2
+ import { Configuration } from './Configuration';
3
+
4
+ export const localizationKey = {
5
+ notification: {
6
+ fine: {
7
+ new: {
8
+ title: 'notification.fine.new.title',
9
+ body: 'notification.fine.new.body'
10
+ },
11
+ reminder: {
12
+ title: 'notification.fine.reminder.title',
13
+ body: 'notification.fine.reminder.body'
14
+ },
15
+ stateChange: {
16
+ title: 'notification.fine.state-change.title',
17
+ bodyPayed: 'notification.fine.state-change.body-payed',
18
+ bodyUnpayed: 'notification.fine.state-change.body-unpayed',
19
+ bodyDeleted: 'notification.fine.state-change.body-deleted'
20
+ }
21
+ }
22
+ },
23
+ fineAmount: {
24
+ item: {
25
+ type: {
26
+ crateOfBeer: 'fineAmount.item.type.crateOfBeer'
27
+ }
28
+ }
29
+ },
30
+ fineTemplateRepetition: {
31
+ item: {
32
+ minute: 'fineTemplateRepetition.item.minute',
33
+ day: 'fineTemplateRepetition.item.day',
34
+ item: 'fineTemplateRepetition.item.item',
35
+ count: 'fineTemplateRepetition.item.count'
36
+ }
37
+ },
38
+ payedState: {
39
+ payed: 'payedState.payed',
40
+ notPayed: 'payedState.notPayed'
41
+ },
42
+ userRole: {
43
+ personManager: 'userRole.personManager',
44
+ fineTemplateManager: 'userRole.fineTemplateManager',
45
+ fineManager: 'userRole.fineManager',
46
+ teamManager: 'userRole.teamManager'
47
+ }
48
+ }
49
+
50
+ export const localizationNKey = {
51
+ fineAmount: {
52
+ item: {
53
+ type: {
54
+ crateOfBeer: 'fineAmount.item.type.crateOfBeer?count=%s'
55
+ }
56
+ }
57
+ },
58
+ fineTemplateRepetition: {
59
+ item: {
60
+ minute: 'fineTemplateRepetition.item.minute?count=%s',
61
+ day: 'fineTemplateRepetition.item.day?count=%s',
62
+ item: 'fineTemplateRepetition.item.item?count=%s',
63
+ count: 'fineTemplateRepetition.item.count?count=%s'
64
+ }
65
+ }
66
+ }
67
+
68
+ export class Localization {
69
+
70
+ public static readonly shared = new Localization();
71
+
72
+ private constructor() {
73
+ i18n.configure({
74
+ locales: Configuration.Locale.all,
75
+ defaultLocale: 'en',
76
+ directory: 'src/locales',
77
+ objectNotation: true
78
+ });
79
+ }
80
+
81
+ public setLocale(locale: Configuration.Locale) {
82
+ i18n.setLocale(locale);
83
+ }
84
+
85
+ public get(getKey: (key: typeof localizationKey) => string, ...args: string[]): string {
86
+ const key = getKey(localizationKey);
87
+ return i18n.__(key, ...args);
88
+ }
89
+
90
+ public getN(getKey: (key: typeof localizationNKey) => string, count: number): string {
91
+ const key = getKey(localizationNKey);
92
+ return i18n.__n(key, count);
93
+ }
94
+ }
@@ -1,4 +1,5 @@
1
1
  import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
+ import { Localization } from './Localization';
2
3
 
3
4
  export type PayedState =
4
5
  | 'payed'
@@ -8,5 +9,9 @@ export namespace PayedState {
8
9
 
9
10
  export const all: PayedState[] = ['payed', 'notPayed'];
10
11
 
12
+ export function formatted(state: PayedState): string {
13
+ return Localization.shared.get(key => key.payedState[state]);
14
+ }
15
+
11
16
  export const builder = new ValueTypeBuilder<PayedState>();
12
17
  }
@@ -1,4 +1,5 @@
1
1
  import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
+ import { Localization, localizationKey } from './Localization';
2
3
 
3
4
  export type UserRole =
4
5
  | 'person-manager'
@@ -15,5 +16,15 @@ export namespace UserRole {
15
16
  'team-manager'
16
17
  ];
17
18
 
19
+ export function formatted(role: UserRole): string {
20
+ const localizationKeyMap: Record<UserRole, keyof typeof localizationKey.userRole> = {
21
+ 'person-manager': 'personManager',
22
+ 'fineTemplate-manager': 'fineTemplateManager',
23
+ 'fine-manager': 'fineManager',
24
+ 'team-manager': 'teamManager'
25
+ }
26
+ return Localization.shared.get(key => key.userRole[localizationKeyMap[role]]);
27
+ }
28
+
18
29
  export const builder = new ValueTypeBuilder<UserRole>();
19
30
  }
@@ -4,6 +4,7 @@ export * from './FineAmount';
4
4
  export * from './FineTemplate';
5
5
  export * from './FineTemplateRepetition';
6
6
  export * from './Invitation';
7
+ export * from './Localization';
7
8
  export * from './MoneyAmount';
8
9
  export * from './NotificationProperties';
9
10
  export * from './PayedState';