From 4eec37d4d13f789ffa9e574cc0c48f1aeba31045 Mon Sep 17 00:00:00 2001 From: Ken Sternberg Date: Mon, 8 Jan 2024 15:49:06 -0800 Subject: [PATCH] raw moves toward isolating localization --- web/packages/localization/.eslintignore | 8 + web/packages/localization/.eslintrc.json | 36 +++++ .../localization/.eslintrc.precommit.json | 29 ++++ web/packages/localization/.gitignore | 113 ++++++++++++++ web/packages/localization/.prettierignore | 11 ++ web/packages/localization/.prettierrc.json | 23 +++ .../lit-localize.json | 0 web/packages/localization/package.json | 142 ++++++++++++++++++ .../src/locale-codes.ts | 0 .../{authentik => localization}/xliff/de.xlf | 0 .../{authentik => localization}/xliff/en.xlf | 0 .../{authentik => localization}/xliff/es.xlf | 0 .../{authentik => localization}/xliff/fr.xlf | 0 .../{authentik => localization}/xliff/ko.xlf | 0 .../{authentik => localization}/xliff/nl.xlf | 0 .../{authentik => localization}/xliff/pl.xlf | 0 .../xliff/pseudo-LOCALE.xlf | 0 .../{authentik => localization}/xliff/tr.xlf | 0 .../xliff/zh-Hans.xlf | 0 .../xliff/zh-Hant.xlf | 0 .../xliff/zh_CN.xlf | 0 .../xliff/zh_TW.xlf | 0 22 files changed, 362 insertions(+) create mode 100644 web/packages/localization/.eslintignore create mode 100644 web/packages/localization/.eslintrc.json create mode 100644 web/packages/localization/.eslintrc.precommit.json create mode 100644 web/packages/localization/.gitignore create mode 100644 web/packages/localization/.prettierignore create mode 100644 web/packages/localization/.prettierrc.json rename web/packages/{authentik => localization}/lit-localize.json (100%) create mode 100644 web/packages/localization/package.json rename web/packages/{authentik => localization}/src/locale-codes.ts (100%) rename web/packages/{authentik => localization}/xliff/de.xlf (100%) rename web/packages/{authentik => localization}/xliff/en.xlf (100%) rename web/packages/{authentik => localization}/xliff/es.xlf (100%) rename web/packages/{authentik => localization}/xliff/fr.xlf (100%) rename web/packages/{authentik => localization}/xliff/ko.xlf (100%) rename web/packages/{authentik => localization}/xliff/nl.xlf (100%) rename web/packages/{authentik => localization}/xliff/pl.xlf (100%) rename web/packages/{authentik => localization}/xliff/pseudo-LOCALE.xlf (100%) rename web/packages/{authentik => localization}/xliff/tr.xlf (100%) rename web/packages/{authentik => localization}/xliff/zh-Hans.xlf (100%) rename web/packages/{authentik => localization}/xliff/zh-Hant.xlf (100%) rename web/packages/{authentik => localization}/xliff/zh_CN.xlf (100%) rename web/packages/{authentik => localization}/xliff/zh_TW.xlf (100%) diff --git a/web/packages/localization/.eslintignore b/web/packages/localization/.eslintignore new file mode 100644 index 000000000..773a27bf1 --- /dev/null +++ b/web/packages/localization/.eslintignore @@ -0,0 +1,8 @@ +# don't ever lint node_modules +node_modules +# don't lint build output (make sure it's set to your correct build folder name) +dist +# don't lint nyc coverage output +coverage +src/locale-codes.ts +storybook-static/ diff --git a/web/packages/localization/.eslintrc.json b/web/packages/localization/.eslintrc.json new file mode 100644 index 000000000..fdae375c6 --- /dev/null +++ b/web/packages/localization/.eslintrc.json @@ -0,0 +1,36 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:lit/recommended", + "plugin:custom-elements/recommended", + "plugin:storybook/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": ["@typescript-eslint", "lit", "custom-elements"], + "ignorePatterns": ["authentik-live-tests/**"], + "rules": { + "indent": "off", + "linebreak-style": ["error", "unix"], + "quotes": ["error", "double", { "avoidEscape": true }], + "semi": ["error", "always"], + "@typescript-eslint/ban-ts-comment": "off", + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_", + "caughtErrorsIgnorePattern": "^_" + } + ] + } +} diff --git a/web/packages/localization/.eslintrc.precommit.json b/web/packages/localization/.eslintrc.precommit.json new file mode 100644 index 000000000..1e2b810a1 --- /dev/null +++ b/web/packages/localization/.eslintrc.precommit.json @@ -0,0 +1,29 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:lit/recommended", + "plugin:custom-elements/recommended", + "plugin:storybook/recommended", + "plugin:sonarjs/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": ["@typescript-eslint", "lit", "custom-elements", "sonarjs"], + "rules": { + "indent": "off", + "linebreak-style": ["error", "unix"], + "quotes": ["error", "double", { "avoidEscape": true }], + "semi": ["error", "always"], + "@typescript-eslint/ban-ts-comment": "off", + "sonarjs/cognitive-complexity": ["error", 9], + "sonarjs/no-nested-template-literals": "off" + } +} diff --git a/web/packages/localization/.gitignore b/web/packages/localization/.gitignore new file mode 100644 index 000000000..f11bf366d --- /dev/null +++ b/web/packages/localization/.gitignore @@ -0,0 +1,113 @@ + +# Created by https://www.gitignore.io/api/node +# Edit at https://www.gitignore.io/?templates=node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt +dist + +# Uncomment the public line if your project uses Gatsby +# https://nextjs.org/blog/next-9-1#public-directory-support +# https://create-react-app.dev/docs/using-the-public-folder/#docsNav +# public + +# Storybook build outputs +.out +.storybook-out + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# Temporary folders +tmp/ +temp/ + +# End of https://www.gitignore.io/api/node +api/** +storybook-static/ +scripts/*.mjs +scripts/*.js diff --git a/web/packages/localization/.prettierignore b/web/packages/localization/.prettierignore new file mode 100644 index 000000000..0e7baef47 --- /dev/null +++ b/web/packages/localization/.prettierignore @@ -0,0 +1,11 @@ +# don't ever lint node_modules +node_modules +# don't lint build output (make sure it's set to your correct build folder name) +dist +# don't lint nyc coverage output +coverage +# Import order matters +poly.ts +src/locale-codes.ts +src/locales/ +storybook-static/ diff --git a/web/packages/localization/.prettierrc.json b/web/packages/localization/.prettierrc.json new file mode 100644 index 000000000..0a4c18708 --- /dev/null +++ b/web/packages/localization/.prettierrc.json @@ -0,0 +1,23 @@ +{ + "arrowParens": "always", + "bracketSpacing": true, + "embeddedLanguageFormatting": "auto", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxSingleQuote": false, + "printWidth": 100, + "proseWrap": "preserve", + "quoteProps": "consistent", + "requirePragma": false, + "semi": true, + "singleQuote": false, + "tabWidth": 4, + "trailingComma": "all", + "useTabs": false, + "vueIndentScriptAndStyle": false, + "plugins": ["@trivago/prettier-plugin-sort-imports"], + "importOrder": ["^(@?)lit(.*)$", "\\.css$", "^@goauthentik/api$", "^[./]"], + "importOrderSeparation": true, + "importOrderSortSpecifiers": true, + "importOrderParserPlugins": ["typescript", "classProperties", "decorators-legacy"] +} diff --git a/web/packages/authentik/lit-localize.json b/web/packages/localization/lit-localize.json similarity index 100% rename from web/packages/authentik/lit-localize.json rename to web/packages/localization/lit-localize.json diff --git a/web/packages/localization/package.json b/web/packages/localization/package.json new file mode 100644 index 000000000..c9c00461e --- /dev/null +++ b/web/packages/localization/package.json @@ -0,0 +1,142 @@ +{ + "name": "@goauthentik/web", + "version": "0.0.0", + "private": true, + "license": "MIT", + "scripts": { + "extract-locales": "lit-localize extract", + "build-locales": "run-s build-locales:build", + "build-locales:build": "lit-localize build", + "build-locales:repair": "prettier --write ./src/locale-codes.ts", + "rollup:build": "cross-env NODE_OPTIONS='--max_old_space_size=4096' rollup -c ./rollup.config.mjs", + "rollup:build-proxy": "cross-env NODE_OPTIONS='--max_old_space_size=4096' rollup -c ./rollup.proxy.mjs", + "rollup:watch": "cross-env NODE_OPTIONS='--max_old_space_size=4096' rollup -c -w", + "build": "run-s build-locales rollup:build", + "build-proxy": "run-s build-locales rollup:build-proxy", + "watch": "run-s build-locales rollup:watch", + "lint": "eslint . --max-warnings 0 --fix", + "lint:precommit": "eslint --max-warnings 0 --config ./.eslintrc.precommit.json $(git status --porcelain . | sed -n '/^[ M?][M?].*\\.[tj][s]$/s/^.*\\/packages\\/authentik\\///p') ", + "lint:spelling": "codespell -D - -D ../../../.github/codespell-dictionary.txt -I ../../../.github/codespell-words.txt -S './src/locales/**' ./src -s", + "lit-analyse": "lit-analyzer src", + "precommit": "run-s tsc lit-analyse lint:precommit lint:spelling prettier", + "prequick": "run-s tsc:execute lit-analyse lint:precommit lint:spelling", + "prettier-check": "prettier --check .", + "prettier": "prettier --write .", + "pseudolocalize:build-extract-script": "cd scripts && tsc --esModuleInterop --module es2020 --target es2020 --moduleResolution 'node' pseudolocalize.ts && mv pseudolocalize.js pseudolocalize.mjs", + "pseudolocalize:extract": "node scripts/pseudolocalize.mjs", + "pseudolocalize": "run-s pseudolocalize:build-extract-script pseudolocalize:extract", + "tsc:execute": "tsc --noEmit -p .", + "tsc": "run-s build-locales tsc:execute", + "storybook": "storybook dev -p 6006", + "storybook:build": "cross-env NODE_OPTIONS='--max_old_space_size=4096' storybook build", + "storybook:build-import-map": "run-s storybook:build-import-map-script storybook:run-import-map-script", + "storybook:build-import-map-script": "cd scripts && tsc --esModuleInterop --module es2020 --target es2020 --moduleResolution 'node' build-storybook-import-maps.ts && mv build-storybook-import-maps.js build-storybook-import-maps.mjs", + "storybook:run-import-map-script": "node scripts/build-storybook-import-maps.mjs" + }, + "dependencies": { + "@codemirror/lang-html": "^6.4.7", + "@codemirror/lang-javascript": "^6.2.1", + "@codemirror/lang-python": "^6.1.3", + "@codemirror/lang-xml": "^6.0.2", + "@codemirror/legacy-modes": "^6.3.3", + "@codemirror/theme-one-dark": "^6.1.2", + "@formatjs/intl-listformat": "^7.5.3", + "@fortawesome/fontawesome-free": "^6.5.1", + "@goauthentik/api": "^2023.10.5-1704382057", + "@lit-labs/context": "^0.4.0", + "@lit-labs/task": "^3.1.0", + "@lit/localize": "^0.11.4", + "@open-wc/lit-helpers": "^0.6.0", + "@patternfly/elements": "^2.4.0", + "@patternfly/patternfly": "^4.224.2", + "@sentry/browser": "^7.92.0", + "@sentry/tracing": "^7.92.0", + "@webcomponents/webcomponentsjs": "^2.8.0", + "base64-js": "^1.5.1", + "chart.js": "^4.4.1", + "chartjs-adapter-moment": "^1.0.1", + "codemirror": "^6.0.1", + "construct-style-sheets-polyfill": "^3.1.0", + "core-js": "^3.35.0", + "country-flag-icons": "^1.5.9", + "fuse.js": "^7.0.0", + "guacamole-common-js": "^1.5.0", + "lit": "^2.8.0", + "mermaid": "^10.6.1", + "rapidoc": "^9.3.4", + "style-mod": "^4.1.0", + "webcomponent-qr-code": "^1.2.0", + "yaml": "^2.3.4" + }, + "devDependencies": { + "@babel/core": "^7.23.7", + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/plugin-proposal-decorators": "^7.23.7", + "@babel/plugin-transform-private-methods": "^7.23.3", + "@babel/plugin-transform-private-property-in-object": "^7.23.4", + "@babel/plugin-transform-runtime": "^7.23.7", + "@babel/preset-env": "^7.23.7", + "@babel/preset-typescript": "^7.23.3", + "@hcaptcha/types": "^1.0.3", + "@jackfranklin/rollup-plugin-markdown": "^0.4.0", + "@jeysal/storybook-addon-css-user-preferences": "^0.2.0", + "@lit/localize-tools": "^0.7.1", + "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-replace": "^5.0.5", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.5", + "@storybook/addon-essentials": "^7.6.7", + "@storybook/addon-links": "^7.6.7", + "@storybook/api": "^7.6.7", + "@storybook/blocks": "^7.6.4", + "@storybook/manager-api": "^7.6.7", + "@storybook/web-components": "^7.6.7", + "@storybook/web-components-vite": "^7.6.7", + "@trivago/prettier-plugin-sort-imports": "^4.3.0", + "@types/chart.js": "^2.9.41", + "@types/codemirror": "5.60.15", + "@types/grecaptcha": "^3.0.7", + "@types/guacamole-common-js": "1.5.2", + "@typescript-eslint/eslint-plugin": "^6.18.0", + "@typescript-eslint/parser": "^6.18.0", + "babel-plugin-macros": "^3.1.0", + "babel-plugin-tsconfig-paths": "^1.0.3", + "cross-env": "^7.0.3", + "eslint": "^8.56.0", + "eslint-config-google": "^0.14.0", + "eslint-plugin-custom-elements": "0.0.8", + "eslint-plugin-lit": "^1.11.0", + "eslint-plugin-sonarjs": "^0.23.0", + "eslint-plugin-storybook": "^0.6.15", + "glob": "^10.3.10", + "lit-analyzer": "^2.0.2", + "npm-run-all": "^4.1.5", + "prettier": "^3.1.1", + "pseudolocale": "^2.0.0", + "pyright": "=1.1.338", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "rollup": "^4.9.4", + "rollup-plugin-copy": "^3.5.0", + "rollup-plugin-cssimport": "^1.0.3", + "rollup-plugin-modify": "^3.0.0", + "rollup-plugin-postcss-lit": "^2.1.0", + "storybook": "^7.6.7", + "storybook-addon-mock": "^4.3.0", + "ts-lit-plugin": "^2.0.1", + "tslib": "^2.6.2", + "turnstile-types": "^1.2.0", + "typescript": "^5.3.3", + "vite-tsconfig-paths": "^4.2.3" + }, + "optionalDependencies": { + "@esbuild/darwin-arm64": "^0.19.11", + "@esbuild/linux-amd64": "^0.18.11", + "@esbuild/linux-arm64": "^0.19.11" + }, + "engines": { + "node": ">=20" + } +} diff --git a/web/packages/authentik/src/locale-codes.ts b/web/packages/localization/src/locale-codes.ts similarity index 100% rename from web/packages/authentik/src/locale-codes.ts rename to web/packages/localization/src/locale-codes.ts diff --git a/web/packages/authentik/xliff/de.xlf b/web/packages/localization/xliff/de.xlf similarity index 100% rename from web/packages/authentik/xliff/de.xlf rename to web/packages/localization/xliff/de.xlf diff --git a/web/packages/authentik/xliff/en.xlf b/web/packages/localization/xliff/en.xlf similarity index 100% rename from web/packages/authentik/xliff/en.xlf rename to web/packages/localization/xliff/en.xlf diff --git a/web/packages/authentik/xliff/es.xlf b/web/packages/localization/xliff/es.xlf similarity index 100% rename from web/packages/authentik/xliff/es.xlf rename to web/packages/localization/xliff/es.xlf diff --git a/web/packages/authentik/xliff/fr.xlf b/web/packages/localization/xliff/fr.xlf similarity index 100% rename from web/packages/authentik/xliff/fr.xlf rename to web/packages/localization/xliff/fr.xlf diff --git a/web/packages/authentik/xliff/ko.xlf b/web/packages/localization/xliff/ko.xlf similarity index 100% rename from web/packages/authentik/xliff/ko.xlf rename to web/packages/localization/xliff/ko.xlf diff --git a/web/packages/authentik/xliff/nl.xlf b/web/packages/localization/xliff/nl.xlf similarity index 100% rename from web/packages/authentik/xliff/nl.xlf rename to web/packages/localization/xliff/nl.xlf diff --git a/web/packages/authentik/xliff/pl.xlf b/web/packages/localization/xliff/pl.xlf similarity index 100% rename from web/packages/authentik/xliff/pl.xlf rename to web/packages/localization/xliff/pl.xlf diff --git a/web/packages/authentik/xliff/pseudo-LOCALE.xlf b/web/packages/localization/xliff/pseudo-LOCALE.xlf similarity index 100% rename from web/packages/authentik/xliff/pseudo-LOCALE.xlf rename to web/packages/localization/xliff/pseudo-LOCALE.xlf diff --git a/web/packages/authentik/xliff/tr.xlf b/web/packages/localization/xliff/tr.xlf similarity index 100% rename from web/packages/authentik/xliff/tr.xlf rename to web/packages/localization/xliff/tr.xlf diff --git a/web/packages/authentik/xliff/zh-Hans.xlf b/web/packages/localization/xliff/zh-Hans.xlf similarity index 100% rename from web/packages/authentik/xliff/zh-Hans.xlf rename to web/packages/localization/xliff/zh-Hans.xlf diff --git a/web/packages/authentik/xliff/zh-Hant.xlf b/web/packages/localization/xliff/zh-Hant.xlf similarity index 100% rename from web/packages/authentik/xliff/zh-Hant.xlf rename to web/packages/localization/xliff/zh-Hant.xlf diff --git a/web/packages/authentik/xliff/zh_CN.xlf b/web/packages/localization/xliff/zh_CN.xlf similarity index 100% rename from web/packages/authentik/xliff/zh_CN.xlf rename to web/packages/localization/xliff/zh_CN.xlf diff --git a/web/packages/authentik/xliff/zh_TW.xlf b/web/packages/localization/xliff/zh_TW.xlf similarity index 100% rename from web/packages/authentik/xliff/zh_TW.xlf rename to web/packages/localization/xliff/zh_TW.xlf