@kopynator/angular 1.0.0 → 1.0.3

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.
package/README.md CHANGED
@@ -18,22 +18,45 @@ npm install @kopynator/core @kopynator/angular
18
18
  In your `app.config.ts`:
19
19
 
20
20
  ```typescript
21
- import { KOPY_CONFIG } from '@kopynator/angular';
21
+ import { provideKopynator } from '@kopynator/angular';
22
22
 
23
23
  export const appConfig: ApplicationConfig = {
24
24
  providers: [
25
- {
26
- provide: KOPY_CONFIG,
27
- useValue: {
28
- apiKey: 'YOUR_TOKEN',
29
- projectId: 'YOUR_PROJECT_ID',
30
- defaultLocale: 'en'
31
- }
32
- }
25
+ provideKopynator({
26
+ apiKey: 'YOUR_API_KEY', // Get it from https://www.kopynator.com
27
+ defaultLocale: 'en',
28
+ mode: 'live',
29
+ languages: ['es', 'en']
30
+ })
33
31
  ]
34
32
  };
35
33
  ```
36
34
 
35
+ #### Configuration Options
36
+
37
+ | Option | Type | Description |
38
+ |---|---|---|
39
+ | `apiKey` | `string` | **Required**. Your public project token found at [kopynator.com](https://www.kopynator.com). |
40
+ | `defaultLocale` | `string` | **Required**. The fallback language if no other is detected (e.g. 'en'). |
41
+ | `languages` | `string[]` | **Required for 'local' mode**. Array of supported language codes. |
42
+ | `mode` | `'local' \| 'hybrid' \| 'live'` | Determines how translations are loaded. See below. |
43
+
44
+ #### Loading Modes
45
+
46
+ 1. **`local`**:
47
+ * **Offline First**. Only loads JSON files from your `assets/i18n` folder.
48
+ * Does **not** make any network requests to Kopynator API.
49
+ * Ideal for development without internet or strict offline requirements.
50
+
51
+ 2. **`live`**:
52
+ * **Cloud First**. Fetches the latest translations directly from the Kopynator CDN/API.
53
+ * Ensures users always see the most up-to-date content without deploying a new version of your app.
54
+ * Requires internet connection.
55
+
56
+ 3. **`hybrid`** (Recommended):
57
+ * **Best of Both Worlds**. First loads your local JSON files (instant render), then fetches updates from the Cloud in the background.
58
+ * Merges both sources, giving priority to the Cloud for any new or updated keys.
59
+
37
60
  ### 2. In Templates
38
61
  ```html
39
62
  <!-- Using Pipe -->
@@ -1,5 +1,5 @@
1
1
  import * as _angular_core from '@angular/core';
2
- import { InjectionToken, PipeTransform, ChangeDetectorRef, OnChanges, ElementRef, SimpleChanges } from '@angular/core';
2
+ import { InjectionToken, EnvironmentProviders, PipeTransform, ChangeDetectorRef, OnChanges, ElementRef, SimpleChanges } from '@angular/core';
3
3
  import { KopyConfig } from '@kopynator/core';
4
4
 
5
5
  declare const KOPY_CONFIG: InjectionToken<KopyConfig>;
@@ -13,6 +13,7 @@ declare class KopyService {
13
13
  setLocale(locale: string): Promise<void>;
14
14
  t(key: string, params?: Record<string, any>): string;
15
15
  }
16
+ declare function provideKopynator(config: KopyConfig): EnvironmentProviders;
16
17
 
17
18
  declare class KopyPipe implements PipeTransform {
18
19
  private kopyService;
@@ -31,4 +32,4 @@ declare class KopyDirective implements OnChanges {
31
32
  private render;
32
33
  }
33
34
 
34
- export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService };
35
+ export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService, provideKopynator };
@@ -1,5 +1,5 @@
1
1
  import * as _angular_core from '@angular/core';
2
- import { InjectionToken, PipeTransform, ChangeDetectorRef, OnChanges, ElementRef, SimpleChanges } from '@angular/core';
2
+ import { InjectionToken, EnvironmentProviders, PipeTransform, ChangeDetectorRef, OnChanges, ElementRef, SimpleChanges } from '@angular/core';
3
3
  import { KopyConfig } from '@kopynator/core';
4
4
 
5
5
  declare const KOPY_CONFIG: InjectionToken<KopyConfig>;
@@ -13,6 +13,7 @@ declare class KopyService {
13
13
  setLocale(locale: string): Promise<void>;
14
14
  t(key: string, params?: Record<string, any>): string;
15
15
  }
16
+ declare function provideKopynator(config: KopyConfig): EnvironmentProviders;
16
17
 
17
18
  declare class KopyPipe implements PipeTransform {
18
19
  private kopyService;
@@ -31,4 +32,4 @@ declare class KopyDirective implements OnChanges {
31
32
  private render;
32
33
  }
33
34
 
34
- export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService };
35
+ export { KOPY_CONFIG, KopyDirective, KopyPipe, KopyService, provideKopynator };
@@ -32,7 +32,8 @@ __export(public_api_exports, {
32
32
  KOPY_CONFIG: () => KOPY_CONFIG,
33
33
  KopyDirective: () => KopyDirective,
34
34
  KopyPipe: () => KopyPipe,
35
- KopyService: () => KopyService
35
+ KopyService: () => KopyService,
36
+ provideKopynator: () => provideKopynator
36
37
  });
37
38
  module.exports = __toCommonJS(public_api_exports);
38
39
 
@@ -69,6 +70,12 @@ KopyService = __decorateClass([
69
70
  }),
70
71
  __decorateParam(0, (0, import_core.Inject)(KOPY_CONFIG))
71
72
  ], KopyService);
73
+ function provideKopynator(config) {
74
+ return (0, import_core.makeEnvironmentProviders)([
75
+ { provide: KOPY_CONFIG, useValue: config },
76
+ KopyService
77
+ ]);
78
+ }
72
79
 
73
80
  // src/lib/kopy.pipe.ts
74
81
  var import_core3 = require("@angular/core");
@@ -122,5 +129,6 @@ KopyDirective = __decorateClass([
122
129
  KOPY_CONFIG,
123
130
  KopyDirective,
124
131
  KopyPipe,
125
- KopyService
132
+ KopyService,
133
+ provideKopynator
126
134
  });
@@ -11,7 +11,7 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
12
12
 
13
13
  // src/lib/kopy.service.ts
14
- import { Injectable, Inject, InjectionToken, signal } from "@angular/core";
14
+ import { Injectable, Inject, InjectionToken, signal, makeEnvironmentProviders } from "@angular/core";
15
15
  import { Kopynator } from "@kopynator/core";
16
16
  var KOPY_CONFIG = new InjectionToken("KOPY_CONFIG");
17
17
  var KopyService = class {
@@ -43,6 +43,12 @@ KopyService = __decorateClass([
43
43
  }),
44
44
  __decorateParam(0, Inject(KOPY_CONFIG))
45
45
  ], KopyService);
46
+ function provideKopynator(config) {
47
+ return makeEnvironmentProviders([
48
+ { provide: KOPY_CONFIG, useValue: config },
49
+ KopyService
50
+ ]);
51
+ }
46
52
 
47
53
  // src/lib/kopy.pipe.ts
48
54
  import { Pipe } from "@angular/core";
@@ -95,5 +101,6 @@ export {
95
101
  KOPY_CONFIG,
96
102
  KopyDirective,
97
103
  KopyPipe,
98
- KopyService
104
+ KopyService,
105
+ provideKopynator
99
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopynator/angular",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "main": "./dist/public-api.js",
5
5
  "module": "./dist/public-api.mjs",
6
6
  "types": "./dist/public-api.d.ts",
@@ -33,6 +33,9 @@
33
33
  "typescript": "^5.0.0"
34
34
  },
35
35
  "scripts": {
36
- "build": "tsup src/public-api.ts --format cjs,esm --dts --clean --external @angular/core,@angular/common,@kopynator/core"
36
+ "build": "tsup src/public-api.ts --format cjs,esm --dts --clean --external @angular/core,@angular/common,@kopynator/core",
37
+ "release:patch": "npm version patch",
38
+ "release:minor": "npm version minor",
39
+ "release:major": "npm version major"
37
40
  }
38
41
  }