Skip to content

Commit

Permalink
added base localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
jagankumar-egov committed Jul 2, 2024
1 parent 125b747 commit 2acd8ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
21 changes: 15 additions & 6 deletions micro-frontends/sample/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Use Node.js base image with version 16
# Stage 1: Fetch locales and build the app
FROM node:20 AS build

# Set working directory
Expand All @@ -17,11 +17,11 @@ ENV COMMIT_ID=$COMMIT_ID
# Copy package.json and yarn.lock (if exists)
COPY package.json ./

# Clean up node_modules and yarn.lock
RUN rm -rf node_modules/

RUN rm -rf yarn.lock

# clear cache
# Clear yarn cache
RUN yarn cache clean

# Install dependencies
Expand All @@ -33,15 +33,24 @@ LABEL commit_id=$COMMIT_ID
# Copy the rest of the application
COPY . .

# Build the React app with Webpack
# Fetch locales before building the app
COPY fetch-locales.js .
RUN node fetch-locales.js

# Build the React app with Vite
RUN yarn build

# Stage 2: Serve the built app using nginx
FROM nginx:mainline-alpine

# Define the work directory for nginx
ENV WORK_DIR=/var/web/sample-ui

# Create the work directory
RUN mkdir -p ${WORK_DIR}


# Copy the build files from the previous stage
COPY --from=build /app/dist ${WORK_DIR}/
COPY --from=build /app/docker/nginx.conf /etc/nginx/conf.d/default.conf

# Copy the nginx configuration file
COPY --from=build /app/docker/nginx.conf /etc/nginx/conf.d/default.conf
27 changes: 27 additions & 0 deletions micro-frontends/sample/fetch-locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const axios = require('axios');
const fs = require('fs');
const path = require('path');

const locales = [
{ lang: 'en', url: 'https://api.example.com/locales/en' },
{ lang: 'fr', url: 'https://api.example.com/locales/fr' },
{ lang: 'de', url: 'https://api.example.com/locales/de' }
];

const fetchLocales = async () => {
for (const locale of locales) {
try {
const response = await axios.get(locale.url);
const dir = path.join(__dirname, 'public', 'locales', locale.lang);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(path.join(dir, 'translation.json'), JSON.stringify(response.data, null, 2));
console.log(`Locale ${locale.lang} saved.`);
} catch (error) {
console.error(`Error fetching locale ${locale.lang}:`, error);
}
}
};

fetchLocales();

0 comments on commit 2acd8ff

Please sign in to comment.