create-sitecore-jss 22.2.0-canary.55 → 22.2.0-canary.57

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.
@@ -54,9 +54,7 @@ const initRunner = (initializers, args) => __awaiter(void 0, void 0, void 0, fun
54
54
  args.silent || console.log(chalk_1.default.cyan(`Initializing '${init}'...`));
55
55
  const response = yield initializer.init(args);
56
56
  // We can have multiple appNames if base template requires to setup an additional standalone app (e.g. XM Cloud proxy)
57
- if (initializer.isBase) {
58
- appNames.add(response.appName);
59
- }
57
+ appNames.add(response.appName);
60
58
  nextStepsArr = [...nextStepsArr, ...((_a = response.nextSteps) !== null && _a !== void 0 ? _a : [])];
61
59
  // process any returned initializers
62
60
  if (response.initializers && response.initializers.length > 0) {
@@ -1,6 +1,6 @@
1
1
  import { APP_ID, NgModule, TransferState } from '@angular/core';
2
2
  import { APP_BASE_HREF } from '@angular/common';
3
- import { HttpClientModule, HttpClient } from '@angular/common/http';
3
+ import { HttpClientModule } from '@angular/common/http';
4
4
  import { RoutingModule } from './routing/routing.module';
5
5
  import { JssLayoutService } from './layout/jss-layout.service';
6
6
  import { AppComponentsModule } from './components/app-components.module';
@@ -22,7 +22,7 @@ import { JssContextService } from './jss-context.service';
22
22
  provide: TranslateLoader,
23
23
  useFactory: (transferState: TransferState) =>
24
24
  new JssTranslationClientLoaderService(new JssTranslationLoaderService(), transferState),
25
- deps: [HttpClient, TransferState],
25
+ deps: [TransferState],
26
26
  },
27
27
  }),
28
28
  AppComponentsModule,
@@ -1,4 +1,4 @@
1
- import { NgModule } from '@angular/core';
1
+ import { NgModule, TransferState } from '@angular/core';
2
2
  import { ServerModule } from '@angular/platform-server';
3
3
  import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
4
4
 
@@ -18,11 +18,14 @@ import { JssTranslationServerLoaderService } from './i18n/jss-translation-server
18
18
  // <-- *Important* to get translation values server-side
19
19
  loader: {
20
20
  provide: TranslateLoader,
21
- useFactory: (ssrViewBag: {
22
- [key: string]: unknown;
23
- dictionary: { [key: string]: string };
24
- }) => new JssTranslationServerLoaderService(ssrViewBag),
25
- deps: ['JSS_SERVER_VIEWBAG'],
21
+ useFactory: (
22
+ ssrViewBag: {
23
+ [key: string]: unknown;
24
+ dictionary: { [key: string]: string };
25
+ },
26
+ transferState: TransferState
27
+ ) => new JssTranslationServerLoaderService(ssrViewBag, transferState),
28
+ deps: ['JSS_SERVER_VIEWBAG', TransferState],
26
29
  },
27
30
  }),
28
31
  ],
@@ -1,21 +1,22 @@
1
- import { makeStateKey, Injectable, TransferState } from '@angular/core';
1
+ import { Injectable, TransferState } from '@angular/core';
2
2
  import { TranslateLoader } from '@ngx-translate/core';
3
- import { EMPTY, of } from 'rxjs';
4
-
5
- export const dictionaryStateKey = makeStateKey<{ [key: string]: string }>('jssDictionary');
3
+ import { DictionaryPhrases } from '@sitecore-jss/sitecore-jss-angular';
4
+ import { EMPTY, Observable, of } from 'rxjs';
5
+ import { JssTranslationLoaderService } from './jss-translation-loader.service';
6
+ import { dictionaryStateKey } from './jss-translation-server-loader.service';
6
7
 
7
8
  @Injectable()
8
9
  export class JssTranslationClientLoaderService implements TranslateLoader {
9
- constructor(private fallbackLoader: TranslateLoader, private transferState: TransferState) {}
10
+ constructor(
11
+ private fallbackLoader: JssTranslationLoaderService,
12
+ private transferState: TransferState
13
+ ) {}
10
14
 
11
- getTranslation(lang: string) {
12
- const storedDictionary = this.transferState.get<{ [key: string]: string } | null>(
13
- dictionaryStateKey,
14
- null
15
- );
15
+ getTranslation(lang: string): Observable<DictionaryPhrases> {
16
+ const dictionary = this.transferState.get(dictionaryStateKey, null);
16
17
 
17
- if (storedDictionary !== null && Object.keys(storedDictionary).length > 0) {
18
- return of(storedDictionary);
18
+ if (dictionary) {
19
+ return of(dictionary);
19
20
  }
20
21
 
21
22
  if (!this.fallbackLoader) {
@@ -1,17 +1,29 @@
1
- import { Inject, Injectable } from '@angular/core';
1
+ import { Inject, Injectable, makeStateKey, StateKey, TransferState } from '@angular/core';
2
2
  import { TranslateLoader } from '@ngx-translate/core';
3
+ import { DictionaryPhrases } from '@sitecore-jss/sitecore-jss-angular';
3
4
  import { of as observableOf, EMPTY } from 'rxjs';
4
5
 
6
+ export const dictionaryStateKey: StateKey<DictionaryPhrases> = makeStateKey<DictionaryPhrases>(
7
+ 'dictionary'
8
+ );
9
+
5
10
  @Injectable()
6
11
  export class JssTranslationServerLoaderService implements TranslateLoader {
7
12
  constructor(
8
13
  // this initial state from sitecore is injected by server.bundle for "integrated" mode
9
14
  @Inject('JSS_SERVER_VIEWBAG')
10
- private serverViewBag: { [key: string]: unknown; dictionary: { [key: string]: string } }
15
+ private serverViewBag: { [key: string]: unknown; dictionary: DictionaryPhrases },
16
+ private transferState: TransferState
11
17
  ) {}
12
18
  getTranslation(_lang: string) {
13
19
  // read initial dictionary from data injected via server.bundle wrapper
14
20
  const dictionary = this.serverViewBag.dictionary;
21
+
22
+ // set the dictionary in transfer state for the client
23
+ // since for ng-translate there is no obvious way to pass the server side dictionary to the client
24
+ // https://github.com/ngx-translate/core/issues/1207#issuecomment-700741671
25
+ this.transferState.set(dictionaryStateKey, dictionary);
26
+
15
27
  if (dictionary) {
16
28
  return observableOf(dictionary);
17
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sitecore-jss",
3
- "version": "22.2.0-canary.55",
3
+ "version": "22.2.0-canary.57",
4
4
  "description": "Sitecore JSS initializer",
5
5
  "bin": "./dist/index.js",
6
6
  "scripts": {
@@ -63,5 +63,5 @@
63
63
  "ts-node": "^10.9.1",
64
64
  "typescript": "~4.9.5"
65
65
  },
66
- "gitHead": "cc443e1f44d87c6129020a1809066c0c49c5a476"
66
+ "gitHead": "b0e10697a51c57017c5494452bc136f86787726e"
67
67
  }