Skip to content

Commit

Permalink
try to fix ssg again
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Jun 20, 2024
1 parent a39313d commit 09b1fb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/app/_shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HttpClient } from '@angular/common/http';
import { NgSelectModule } from '@ng-select/ng-select';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { of, type Observable } from 'rxjs';
import { environment } from '../../environments/environment';
import { CardTextComponent } from './components/card-text/card-text.component';
import { CardIconComponent } from './components/cardicon/cardicon.component';
Expand All @@ -24,7 +25,18 @@ import { MarkdownPipe } from './pipes/markdown.pipe';
import { ProductNamePipe } from './pipes/productname.pipe';
import { StripSpacesPipe } from './pipes/stripspaces.pipe';

export function httpLoaderFactory(http: HttpClient) {
export class TranslateLocalJSONLoader implements TranslateLoader {
getTranslation(lang: string): Observable<unknown> {
const locales = environment.overrideData.locale;
return of(locales[lang as keyof typeof locales]);
}
}

export function httpOrLocalLoaderFactory(http: HttpClient) {
if (environment.ssg) {
return new TranslateLocalJSONLoader();
}

return new TranslateHttpLoader(http, `${environment.baseUrl}/i18n/`, '.json');
}

Expand Down Expand Up @@ -55,7 +67,7 @@ export function httpLoaderFactory(http: HttpClient) {
defaultLanguage: 'en-US',
loader: {
provide: TranslateLoader,
useFactory: httpLoaderFactory,
useFactory: httpOrLocalLoaderFactory,
deps: [HttpClient],
},
}),
Expand Down
4 changes: 2 additions & 2 deletions src/environments/environment.ssg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as meta from '../../ssgdata/meta.json';
export const environment = {
production: true,
ssg: true,
baseAppUrl: 'http://localhost:4000',
baseAppUrl: 'https://cards.ledergames.com',
baseUrl: 'https://ledercardcdn.seiyria.com',
overrideData: {
cardsMin: (cardsMin as any).default ?? cardsMin,
Expand All @@ -18,7 +18,7 @@ export const environment = {
faq: (faq as any).default ?? faq,
meta: (meta as any).default ?? meta,
locale: {
enUS: (enUS as any).default ?? enUS,
'en-US': (enUS as any).default ?? enUS,
},
},
};

0 comments on commit 09b1fb4

Please sign in to comment.