Skip to content

Commit

Permalink
Feat/select default locale (#4417)
Browse files Browse the repository at this point in the history
* fix change default language

* add env var LOCALE_CODE

* npm run change:add

* Update four-news-glow.md

---------

Co-authored-by: Patryk Andrzejewski <vox3r69@gmail.com>
  • Loading branch information
GabrielZacchi and andrzejewsky committed Nov 17, 2023
1 parent 01707e9 commit 2e22ba1
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-news-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

add env var LOCALE_CODE
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
API_URI=https://demo.saleor.io/graphql/
APP_MOUNT_URI=/
APPS_MARKETPLACE_API_URI=https://apps.saleor.io/api/v2/saleor-apps
APPS_MARKETPLACE_API_URI=https://apps.saleor.io/api/v2/saleor-apps
LOCALE_CODE="EN"
1 change: 1 addition & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
API_URL: "",
APP_MOUNT_URI: "/",
IS_CLOUD_INSTANCE: false,
LOCALE_CODE: "EN",
};
window.process = { cwd: () => "" };
</script>
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ ARG APPS_MARKETPLACE_API_URI
ARG APPS_TUNNEL_URL_KEYWORDS
ARG STATIC_URL
ARG SKIP_SOURCEMAPS
ARG LOCALE_CODE

ENV API_URI ${API_URI:-http://localhost:8000/graphql/}
ENV APP_MOUNT_URI ${APP_MOUNT_URI:-/dashboard/}
ENV APPS_MARKETPLACE_API_URI ${APPS_MARKETPLACE_API_URI:-https://apps.saleor.io/api/v2/saleor-apps}
ENV APPS_TUNNEL_URL_KEYWORDS ${APPS_TUNNEL_URL_KEYWORDS}
ENV STATIC_URL ${STATIC_URL:-/dashboard/}
ENV SKIP_SOURCEMAPS ${SKIP_SOURCEMAPS:-true}
ENV LOCALE_CODE ${LOCALE_CODE:-EN}
RUN npm run build

FROM nginx:stable-alpine as runner
Expand Down
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"APP_MOUNT_URI": {
"description": "URI at which the Dashboard app will be mounted",
"value": "/"
},
"LOCALE_CODE": {
"description": "Locale code to select default language",
"value": "EN"
}
},
"buildpacks": [
Expand Down
1 change: 1 addition & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = async (on, config) => {
config.env.MAILPITURL = process.env.CYPRESS_MAILPITURL;
config.env.grepTags = process.env.CYPRESS_grepTags;
config.baseUrl = process.env.BASE_URL;
config.env.LOCALE_CODE = process.env.LOCALE_CODE;

on("before:browser:launch", (_browser = {}, launchOptions) => {
launchOptions.args.push("--proxy-bypass-list=<-loopback>");
Expand Down
5 changes: 3 additions & 2 deletions src/components/Locale/Locale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ function getKeyValueJson(messages: LocaleMessages): Record<string, string> {
}
}

const defaultLocale = Locale.EN;
const localeCode = process.env.LOCALE_CODE || "EN";
const defaultLocale = Locale[localeCode];

export interface LocaleContextType {
locale: Locale;
Expand All @@ -131,7 +132,7 @@ const LocaleProvider: React.FC = ({ children }) => {

React.useEffect(() => {
async function changeLocale() {
if (locale !== defaultLocale) {
if (locale !== Locale.EN) {
// It seems like Webpack is unable to use aliases for lazy imports
const mod = await import(`../../../locale/${locale}.json`);
setMessages(mod.default);
Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
APPS_MARKETPLACE_API_URI: "<%= APPS_MARKETPLACE_API_URI %>",
APPS_TUNNEL_URL_KEYWORDS: "<%= APPS_TUNNEL_URL_KEYWORDS %>",
IS_CLOUD_INSTANCE: "<%= IS_CLOUD_INSTANCE %>",
LOCALE_CODE: "<%= LOCALE_CODE %>",
};
</script>
</head>
Expand Down
1 change: 1 addition & 0 deletions testUtils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ window.__SALEOR_CONFIG__ = {
APPS_MARKETPLACE_API_URI: "http://localhost:3000",
APPS_TUNNEL_URL_KEYWORDS: ".ngrok.io;.saleor.live",
IS_CLOUD_INSTANCE: "true",
LOCALE_CODE: "EN",
};

process.env.TZ = "UTC";
Expand Down
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare interface Window {
__SALEOR_CONFIG__: {
API_URL: string;
APP_MOUNT_URI: string;
LOCALE_CODE?: string;
APPS_MARKETPLACE_API_URI?: string;
APPS_TUNNEL_URL_KEYWORDS?: string;
IS_CLOUD_INSTANCE?: string;
Expand Down
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default defineConfig(({ command, mode }) => {
DEMO_MODE,
CUSTOM_VERSION,
FLAGS_SERVICE_ENABLED,
LOCALE_CODE,
} = env;

const base = STATIC_URL ?? "/";
Expand All @@ -62,6 +63,7 @@ export default defineConfig(({ command, mode }) => {
APPS_MARKETPLACE_API_URI,
APPS_TUNNEL_URL_KEYWORDS,
IS_CLOUD_INSTANCE,
LOCALE_CODE,
injectOgTags:
DEMO_MODE &&
`
Expand Down Expand Up @@ -142,6 +144,7 @@ export default defineConfig(({ command, mode }) => {
ENVIRONMENT,
DEMO_MODE,
CUSTOM_VERSION,
LOCALE_CODE,
},
},
build: {
Expand Down

0 comments on commit 2e22ba1

Please sign in to comment.