Skip to content

Commit

Permalink
PS-644 shared translations (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem authored Apr 22, 2024
1 parent a88ff31 commit f1a8a21
Show file tree
Hide file tree
Showing 97 changed files with 4,815 additions and 1,327 deletions.
11 changes: 11 additions & 0 deletions bin/dev/translate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. bin/vars.sh

js=(${CLIENT_PROJECTS} ${JS_LIBS})

for a in "${js[@]}"; do
echo " $a:"

(cd "$a" && grep -q "\"translate\":" package.json && pnpm translate)
done
17 changes: 17 additions & 0 deletions bin/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@ lib/php/webhook-bundle
lib/php/workflow
lib/php/workflow-bundle
"

JS_LIBS="
lib/js/api
lib/js/auth
lib/js/core
lib/js/i18n
lib/js/liform-react
lib/js/navigation
lib/js/phrasea-ui
lib/js/react-auth
lib/js/react-form
lib/js/react-hooks
lib/js/react-ps
lib/js/storage
lib/js/theme-editor
lib/js/visual-workflow
"
2 changes: 1 addition & 1 deletion dashboard/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-google-font-loader": "^1.1.0",
"react-i18next": "^13.5.0",
"react-i18next": "^14.1.0",
"vite-plugin-svgr": "^4.2.0"
},
"devDependencies": {
Expand Down
82 changes: 0 additions & 82 deletions databox/client/i18next-scanner.config.js

This file was deleted.

12 changes: 6 additions & 6 deletions databox/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@alchemy/auth": "workspace:*",
"@alchemy/core": "workspace:*",
"@alchemy/navigation": "workspace:*",
"@alchemy/i18n": "workspace:*",
"@alchemy/phrasea-ui": "workspace:*",
"@alchemy/react-auth": "workspace:*",
"@alchemy/react-form": "workspace:*",
Expand Down Expand Up @@ -35,8 +36,6 @@
"flag-icons": "^6.15.0",
"formik": "^2.4.5",
"formik-material-ui": "4.0.0-alpha.2",
"i18next": "^23.10.1",
"i18next-browser-languagedetector": "^6.1.8",
"ismounted": "^0.1.8",
"leaflet": "^1.9.4",
"moment": "^2.30.1",
Expand All @@ -49,7 +48,7 @@
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.51.0",
"react-i18next": "^13.5.0",
"react-i18next": "^14.1.0",
"react-leaflet": "^4.2.1",
"react-nl2br": "^1.0.4",
"react-pdf": "^7.7.1",
Expand All @@ -71,7 +70,7 @@
"lint:fix": "eslint --fix src",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json|cjs|tsx|jsx)\"",
"preview": "vite preview",
"i18n:scan": "mkdir -p ./i18n-scan-tmp && rm -rf ./i18n-scan-tmp && npx tsc --jsx preserve --target ES6 --module es2022 --noEmit false --outDir ./i18n-scan-tmp && npx i18next-scanner"
"translate": "i18next-scanner --config ../../lib/js/i18n/i18next-scanner.config.js"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.2",
Expand All @@ -94,11 +93,12 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-unused-imports": "^3.1.0",
"i18next-scanner": "^3.3.0",
"ts-jest": "^23.10.5",
"typescript": "^5.4.2",
"vite": "^5.1.6",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-svgr": "^4.2.0"
"vite-plugin-svgr": "^4.2.0",
"i18next-scanner": "^4.4.0",
"i18next-scanner-typescript": "^1.2.0"
}
}
50 changes: 5 additions & 45 deletions databox/client/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
import i18n, {ResourceLanguage} from 'i18next';
import {initReactI18next} from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import {defaultLocale, locales} from './lib/locales';
import * as appLangs from './locales/app';
import {createI18N, createNS} from '@alchemy/i18n';
import * as appLangs from '../translations';

const resources: {[language: string]: ResourceLanguage} = {};

function addNS(ns: string, r: {[language: string]: ResourceLanguage}): void {
locales.forEach(l => {
if (!resources[l]) {
resources[l] = {[ns]: r[l]};
} else {
resources[l][ns] = r[l];
}
});
}

addNS('app', appLangs);

i18n.use(LanguageDetector)
.use(initReactI18next)
.init({
defaultNS: 'app',
supportedLngs: locales,
fallbackLng: defaultLocale,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
resources,
});

function normalizeHTMLLocale(l: string): string {
return l.replace(/_/g, '-');
}

function setHtmlLangAttr(l: string): void {
document.documentElement.setAttribute('lang', normalizeHTMLLocale(l));
}

function languageChanged(lng: string): void {
setHtmlLangAttr(lng);
}

languageChanged(i18n.language);
i18n.on('languageChanged', languageChanged);
const i18n = createI18N({
resources: createNS(appLangs),
});

export default i18n;
4 changes: 0 additions & 4 deletions databox/client/src/locales/app.ts

This file was deleted.

36 changes: 0 additions & 36 deletions databox/client/src/locales/en_US/app.json

This file was deleted.

36 changes: 0 additions & 36 deletions databox/client/src/locales/fr_FR/app.json

This file was deleted.

1 change: 0 additions & 1 deletion databox/client/src/store/basketStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const useBasketStore = create<State>((set, getState) => ({
},

hasMore() {
console.log('!!getState().nextUrl', !!getState().nextUrl);
return !!getState().nextUrl;
},

Expand Down
Loading

0 comments on commit f1a8a21

Please sign in to comment.