Skip to content

Instantly share code, notes, and snippets.

View jgcarmona-com's full-sized avatar

Juan G Carmona jgcarmona-com

View GitHub Profile
/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
import { APP_BASE_HREF } from '@angular/common';
import { LOCALE_ID } from '@angular/core';
import '@angular/localize/init';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import { existsSync } from 'fs';
import { join } from 'path';
{
"name": "ourProyectNameGoesHere-server",
"version": "1.0.0",
"private": true,
"description": "",
"keywords": [],
"author": "Juan García Carmona",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
const express = require("express");
const path = require("path");
const getTranslatedServer = (lang) => {
const targetServerPath = path.join(
process.cwd(),
`ourProyectNameGoesHere/server/${lang}`
);
const server = require(`${targetServerPath}/main.js`);
return server.app(lang);
{
"name": "ourProyectNameGoesHere",
"version": "0.1.0",
"scripts": {
"ng": "ng",
"build": "ng build",
"start": "ng serve --aot",
"lint": "ng lint ourProyectNameGoesHere",
"test": "ng test",
"e2e": "ng e2e",
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"ourProyectNameGoesHere": {
"i18n": {
"sourceLocale": "en-US",
"locales": {
"es": {
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Inject, Injectable, LOCALE_ID } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable()
export class LanguageInterceptor implements HttpInterceptor {
currentLocale: string;
constructor(@Inject(LOCALE_ID) public locale: string) {
this.currentLocale = this.locale.split('-', 1)[0];