This commit is contained in:
limon 2025-10-04 11:41:09 -04:00 committed by GitHub
commit e64f6ec2bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 0 deletions

View file

@ -10,12 +10,26 @@ RUN npm run build
FROM nginx:alpine FROM nginx:alpine
ENV DEFAULT_LANG=en
COPY --from=build /app/dist /usr/share/nginx/html COPY --from=build /app/dist /usr/share/nginx/html
RUN sed -i 's/application\/javascript.*js;/application\/javascript js mjs;/' /etc/nginx/mime.types RUN sed -i 's/application\/javascript.*js;/application\/javascript js mjs;/' /etc/nginx/mime.types
RUN sed -i 's|index index.html index.htm;|index index.html index.htm;\n try_files $uri $uri/ /index.html;|' /etc/nginx/conf.d/default.conf RUN sed -i 's|index index.html index.htm;|index index.html index.htm;\n try_files $uri $uri/ /index.html;|' /etc/nginx/conf.d/default.conf
COPY <<'EOF' /docker-entrypoint.d/30-inject-default-lang.sh
#!/bin/sh
set -e
find /usr/share/nginx/html -name "*.html" -exec sed -i \
"s|<head>|<head>\n <script>window.DEFAULT_LANG='${DEFAULT_LANG}';</script>|" {} \;
echo "Injected DEFAULT_LANG=${DEFAULT_LANG} into HTML files"
EOF
RUN chmod +x /docker-entrypoint.d/30-inject-default-lang.sh
EXPOSE 80 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

View file

@ -31,3 +31,9 @@ declare module 'i18next' {
}; };
} }
} }
declare global {
interface Window {
DEFAULT_LANG?: string;
}
}

View file

@ -23,6 +23,30 @@ export type FullI18nKey = {
[K in I18nNamespaces]: `${K}:${ParseKeys<K>}`; [K in I18nNamespaces]: `${K}:${ParseKeys<K>}`;
}[I18nNamespaces]; }[I18nNamespaces];
const currentLang = localStorage.getItem('lang');
const userHasChosenLang = localStorage.getItem('userChosenLang'); // Flag to track if user manually selected
if (
window.DEFAULT_LANG &&
(!currentLang || (!userHasChosenLang && currentLang === 'en'))
) {
const supportedLangs = [
'en',
'de',
'es',
'fr',
'pt',
'ja',
'hi',
'nl',
'ru',
'zh'
];
if (supportedLangs.includes(window.DEFAULT_LANG)) {
localStorage.setItem('lang', window.DEFAULT_LANG);
}
}
i18n i18n
.use(Backend) .use(Backend)
.use(LanguageDetector) .use(LanguageDetector)