mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-06 00:44:57 +05:30
feat(docker): set DEFAULT_LANG at runtime from Docker
This commit is contained in:
parent
159f69125b
commit
0f460d81a1
3 changed files with 42 additions and 0 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -18,6 +18,18 @@ RUN sed -i 's/application\/javascript.*js;/application\/javascript
|
|||
|
||||
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
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
|
|
|||
6
src/@types/i18n.d.ts
vendored
6
src/@types/i18n.d.ts
vendored
|
|
@ -31,3 +31,9 @@ declare module 'i18next' {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
DEFAULT_LANG?: string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,30 @@ export type FullI18nKey = {
|
|||
[K in I18nNamespaces]: `${K}:${ParseKeys<K>}`;
|
||||
}[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
|
||||
.use(Backend)
|
||||
.use(LanguageDetector)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue