@stevenkellner/team-conduct-api 1.0.13 → 1.0.15

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 (36) hide show
  1. package/lib/src/functions/fine/add.js +3 -37
  2. package/lib/src/functions/fine/delete.js +3 -37
  3. package/lib/src/functions/fine/update.js +4 -38
  4. package/lib/src/locales/de.json +69 -0
  5. package/lib/src/locales/en.json +69 -0
  6. package/lib/src/types/FineAmount.d.ts +3 -1
  7. package/lib/src/types/FineAmount.js +10 -42
  8. package/lib/src/types/FineTemplateRepetition.d.ts +2 -0
  9. package/lib/src/types/FineTemplateRepetition.js +8 -0
  10. package/lib/src/types/Localization.d.ts +71 -0
  11. package/lib/src/types/Localization.js +124 -0
  12. package/lib/src/types/PayedState.d.ts +1 -0
  13. package/lib/src/types/PayedState.js +5 -0
  14. package/lib/src/types/UserRole.d.ts +1 -0
  15. package/lib/src/types/UserRole.js +11 -0
  16. package/lib/src/types/index.d.ts +1 -0
  17. package/lib/src/types/index.js +1 -0
  18. package/lib/test/localization-utils.d.ts +12 -0
  19. package/lib/test/localization-utils.js +68 -0
  20. package/lib/test/localization.de.test.d.ts +1 -0
  21. package/lib/test/localization.de.test.js +166 -0
  22. package/lib/test/localization.en.test.d.ts +1 -0
  23. package/lib/test/localization.en.test.js +162 -0
  24. package/lib/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +6 -1
  26. package/src/functions/fine/add.ts +5 -5
  27. package/src/functions/fine/delete.ts +4 -5
  28. package/src/functions/fine/update.ts +5 -6
  29. package/src/locales/de.json +67 -28
  30. package/src/locales/en.json +67 -28
  31. package/src/types/FineAmount.ts +11 -9
  32. package/src/types/FineTemplateRepetition.ts +9 -0
  33. package/src/types/Localization.ts +95 -0
  34. package/src/types/PayedState.ts +5 -0
  35. package/src/types/UserRole.ts +11 -0
  36. package/src/types/index.ts +1 -0
@@ -1,30 +1,69 @@
1
1
  {
2
- "notification": {
3
- "fine": {
4
- "new": {
5
- "title": "%s",
6
- "body": "Du hast eine neue Strafe von %s. Bitte so schnell wie möglich zahlen."
7
- },
8
- "reminder": {
9
- "title": "Du hast noch offene Strafen",
10
- "body": "Bei dir sind noch %s offen. Bitte so schnell wie möglich zahlen."
11
- },
12
- "state-change": {
13
- "title": "Eine deiner Strafen hat sich geändert",
14
- "body-payed": "Du hast eine Strafe von %1$s bezahlt (%2$s).",
15
- "body-unpayed": "%1$s, %2$s ist noch offen.",
16
- "body-deleted": "%1$s, %2$s wurde gelöscht."
17
- }
18
- }
19
- },
20
- "FineAmount": {
21
- "Item": {
22
- "Type": {
23
- "crateOfBeer": {
24
- "singular": "Ein Kasten Bier",
25
- "plural": "%s Kästen Bier"
26
- }
27
- }
28
- }
29
- }
2
+ "notification": {
3
+ "fine": {
4
+ "new": {
5
+ "title": "%s",
6
+ "body": "Du hast eine neue Strafe von %s. Bitte so schnell wie möglich zahlen."
7
+ },
8
+ "reminder": {
9
+ "title": "Du hast noch offene Strafen",
10
+ "body": "Bei dir sind noch %s offen. Bitte so schnell wie möglich zahlen."
11
+ },
12
+ "state-change": {
13
+ "title": "Eine deiner Strafen hat sich geändert",
14
+ "body-payed": "Du hast eine Strafe von %1$s bezahlt (%2$s).",
15
+ "body-unpayed": "%1$s, %2$s ist noch offen.",
16
+ "body-deleted": "%1$s, %2$s wurde gelöscht."
17
+ }
18
+ }
19
+ },
20
+ "fineAmount": {
21
+ "item": {
22
+ "type": {
23
+ "crateOfBeer": "Kasten Bier",
24
+ "crateOfBeer?count=%s": {
25
+ "one": "Ein Kasten Bier",
26
+ "other": "%s Kästen Bier"
27
+ },
28
+ "crateOfBeerWithoutCount?count=%s": {
29
+ "one": "Kasten Bier",
30
+ "other": "Kästen Bier"
31
+ }
32
+ }
33
+ }
34
+ },
35
+ "fineTemplateRepetition": {
36
+ "item": {
37
+ "minute": "Minute",
38
+ "minute?count=%s": {
39
+ "one": "1 Minute",
40
+ "other": "%s Minuten"
41
+ },
42
+ "day": "Tag",
43
+ "day?count=%s": {
44
+ "one": "1 Tag",
45
+ "other": "%s Tage"
46
+ },
47
+ "item": "Teil",
48
+ "item?count=%s": {
49
+ "one": "1 Teil",
50
+ "other": "%s Teile"
51
+ },
52
+ "count": "Anzahl",
53
+ "count?count=%s": {
54
+ "one": "1 mal",
55
+ "other": "%s mal"
56
+ }
57
+ }
58
+ },
59
+ "payedState": {
60
+ "payed": "Bezahlt",
61
+ "notPayed": "Offen"
62
+ },
63
+ "userRole": {
64
+ "personManager": "Personenmanager",
65
+ "fineTemplateManager": "Strafvorlagenmanager",
66
+ "fineManager": "Strafenmanager",
67
+ "teamManager": "Teammanager"
68
+ }
30
69
  }
@@ -1,30 +1,69 @@
1
1
  {
2
- "notification": {
3
- "fine": {
4
- "new": {
5
- "title": "%s",
6
- "body": "You have a new fine of %s. Please pay it as soon as possible."
7
- },
8
- "reminder": {
9
- "title": "You still have outstanding penalties",
10
- "body": "You still have %s outstanding. Please pay as soon as possible."
11
- },
12
- "state-change": {
13
- "title": "One of your penalties has changed",
14
- "body-paid": "You have paid a penalty of %1$s (%2$s).",
15
- "body-unpayed": "%1$s, %2$s are still outstanding.",
16
- "body-deleted": "%1$s, %2$s has been deleted."
17
- }
18
- }
19
- },
20
- "FineAmount": {
21
- "Item": {
22
- "Type": {
23
- "crateOfBeer": {
24
- "singular": "One Crate of Beer",
25
- "plural": "%s Crates of Beer"
26
- }
27
- }
28
- }
29
- }
2
+ "notification": {
3
+ "fine": {
4
+ "new": {
5
+ "title": "%s",
6
+ "body": "You have a new fine of %s. Please pay it as soon as possible."
7
+ },
8
+ "reminder": {
9
+ "title": "You still have outstanding fines",
10
+ "body": "You still have %s outstanding. Please pay as soon as possible."
11
+ },
12
+ "state-change": {
13
+ "title": "One of your fines has changed",
14
+ "body-payed": "You have paid a fine of %1$s (%2$s).",
15
+ "body-unpayed": "%1$s, %2$s is still outstanding.",
16
+ "body-deleted": "%1$s, %2$s has been deleted."
17
+ }
18
+ }
19
+ },
20
+ "fineAmount": {
21
+ "item": {
22
+ "type": {
23
+ "crateOfBeer": "Crate of Beer",
24
+ "crateOfBeer?count=%s": {
25
+ "one": "a crate of beer",
26
+ "other": "%s crates of beer"
27
+ },
28
+ "crateOfBeerWithoutCount?count=%s": {
29
+ "one": "Crate of Beer",
30
+ "other": "Crates of Beer"
31
+ }
32
+ }
33
+ }
34
+ },
35
+ "fineTemplateRepetition": {
36
+ "item": {
37
+ "minute": "Minute",
38
+ "minute?count=%s": {
39
+ "one": "1 minute",
40
+ "other": "%s minutes"
41
+ },
42
+ "day": "Day",
43
+ "day?count=%s": {
44
+ "one": "1 day",
45
+ "other": "%s days"
46
+ },
47
+ "item": "Item",
48
+ "item?count=%s": {
49
+ "one": "1 item",
50
+ "other": "%s items"
51
+ },
52
+ "count": "Count",
53
+ "count?count=%s": {
54
+ "one": "1 time",
55
+ "other": "%s times"
56
+ }
57
+ }
58
+ },
59
+ "payedState": {
60
+ "payed": "Paid",
61
+ "notPayed": "Outstanding"
62
+ },
63
+ "userRole": {
64
+ "personManager": "Person Manager",
65
+ "fineTemplateManager": "Fine Template Manager",
66
+ "fineManager": "Fine Manager",
67
+ "teamManager": "Team Manager"
68
+ }
30
69
  }
@@ -1,7 +1,7 @@
1
1
  import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
2
  import { MoneyAmount } from './MoneyAmount';
3
- import * as i18n from 'i18n';
4
3
  import { Configuration } from './Configuration';
4
+ import { Localization } from './Localization';
5
5
 
6
6
  export type FineAmount =
7
7
  | FineAmount.Money
@@ -51,14 +51,12 @@ export namespace FineAmount {
51
51
  public count: number
52
52
  ) {}
53
53
 
54
- public formatted(configuration: Configuration): string {
55
- const numberFormat = Intl.NumberFormat(configuration.locale, {
56
- minimumFractionDigits: 0,
57
- maximumFractionDigits: 0
58
- });
59
- if (this.count === 1)
60
- return i18n.__(`FineAmount.Item.Type.${this.item}.singular`, numberFormat.format(this.count));
61
- return i18n.__(`FineAmount.Item.Type.${this.item}.plural`, numberFormat.format(this.count));
54
+ public formatted(): string {
55
+ return Localization.shared.getN(key => key.fineAmount.item.type[this.item], this.count);
56
+ }
57
+
58
+ public formattedWithoutCount(): string {
59
+ return Localization.shared.getN(key => key.fineAmount.item.type[`${this.item}WithoutCount`], this.count);
62
60
  }
63
61
 
64
62
  public get flatten(): Item.Flatten {
@@ -78,6 +76,10 @@ export namespace FineAmount {
78
76
  export namespace Type {
79
77
 
80
78
  export const all: Type[] = ['crateOfBeer'];
79
+
80
+ export function formatted(type: Type): string {
81
+ return Localization.shared.get(key => key.fineAmount.item.type[type]);
82
+ }
81
83
  }
82
84
 
83
85
  export type Flatten = {
@@ -1,4 +1,5 @@
1
1
  import { Flattable, ITypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
+ import { Localization } from './Localization';
2
3
 
3
4
  export class FineTemplateRepetition implements Flattable<FineTemplateRepetition.Flatten> {
4
5
 
@@ -7,6 +8,10 @@ export class FineTemplateRepetition implements Flattable<FineTemplateRepetition.
7
8
  public maxCount: number | null
8
9
  ) {}
9
10
 
11
+ public formatted(count: number): string {
12
+ return Localization.shared.getN(key => key.fineTemplateRepetition.item[this.item], count);
13
+ }
14
+
10
15
  public get flatten(): FineTemplateRepetition.Flatten {
11
16
  return {
12
17
  item: this.item,
@@ -32,6 +37,10 @@ export namespace FineTemplateRepetition {
32
37
  'count'
33
38
  ];
34
39
 
40
+ export function formatted(item: Item): string {
41
+ return Localization.shared.get(key => key.fineTemplateRepetition.item[item]);
42
+ }
43
+
35
44
  export const builder = new ValueTypeBuilder<Item>();
36
45
  }
37
46
 
@@ -0,0 +1,95 @@
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
+ crateOfBeerWithoutCount: 'fineAmount.item.type.crateOfBeerWithoutCount?count=%s'
56
+ }
57
+ }
58
+ },
59
+ fineTemplateRepetition: {
60
+ item: {
61
+ minute: 'fineTemplateRepetition.item.minute?count=%s',
62
+ day: 'fineTemplateRepetition.item.day?count=%s',
63
+ item: 'fineTemplateRepetition.item.item?count=%s',
64
+ count: 'fineTemplateRepetition.item.count?count=%s'
65
+ }
66
+ }
67
+ }
68
+
69
+ export class Localization {
70
+
71
+ public static readonly shared = new Localization();
72
+
73
+ private constructor() {
74
+ i18n.configure({
75
+ locales: Configuration.Locale.all,
76
+ defaultLocale: 'en',
77
+ directory: 'src/locales',
78
+ objectNotation: true
79
+ });
80
+ }
81
+
82
+ public setLocale(locale: Configuration.Locale) {
83
+ i18n.setLocale(locale);
84
+ }
85
+
86
+ public get(getKey: (key: typeof localizationKey) => string, ...args: string[]): string {
87
+ const key = getKey(localizationKey);
88
+ return i18n.__(key, ...args);
89
+ }
90
+
91
+ public getN(getKey: (key: typeof localizationNKey) => string, count: number): string {
92
+ const key = getKey(localizationNKey);
93
+ return i18n.__n(key, count);
94
+ }
95
+ }
@@ -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';