diff --git a/.changeset/long-cherries-exercise.md b/.changeset/long-cherries-exercise.md new file mode 100644 index 000000000..671718863 --- /dev/null +++ b/.changeset/long-cherries-exercise.md @@ -0,0 +1,5 @@ +--- +"@studiocms/core": patch +--- + +Translation Updated (PR: #376) diff --git a/.changeset/perfect-hornets-swim.md b/.changeset/perfect-hornets-swim.md new file mode 100644 index 000000000..a325e1055 --- /dev/null +++ b/.changeset/perfect-hornets-swim.md @@ -0,0 +1,17 @@ +--- +"studiocms": patch +"@studiocms/auth": patch +"@studiocms/core": patch +--- + +Introduce Dashboard i18n logic + +- `studiocms` & `@studiocms/core`: + - Introduce new virtual module `studiocms:i18n`: + This module includes utilities for our new i18n system. + - Add new LanguageSelector component + - Add `en-us` translation file. (`packages/studiocms_core/i18n/translations/`) + +- `@studiocms/auth`: + - Update login/signup routes to utilize new i18n translations + - Transition routes to Hybrid type setup, All API routes will remain server rendered, while pages are now prerendered (Server islands when needed). \ No newline at end of file diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..4c6b1adeb --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,5 @@ +# See https://github.com/actions/labeler/tree/main for more information about the labeler action + +translations: + - changed-files: + - any-glob-to-any-file: packages/studiocms_core/src/i18n/translations/* \ No newline at end of file diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 000000000..8a76c8118 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,17 @@ +name: Pull Request Labeler + +on: [pull_request_target] + +permissions: + contents: read + pull-requests: write + +jobs: + label: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 + with: + repo-token: "${{ secrets.STUDIOCMS_SERVICE_TOKEN }}" + configuration-path: .github/labeler.yml + sync-labels: true \ No newline at end of file diff --git a/.github/workflows/translation-changesets.yml b/.github/workflows/translation-changesets.yml new file mode 100644 index 000000000..f2470367e --- /dev/null +++ b/.github/workflows/translation-changesets.yml @@ -0,0 +1,46 @@ +name: Translation Changesets + +on: + pull_request: + types: [labeled, synchronize] + +permissions: + contents: write + +jobs: + build-translation-changesets: + runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'translations') && github.event.pull_request.user.login == 'studiocms-no-reply' + steps: + - name: Checkout Repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.STUDIOCMS_SERVICE_TOKEN }} + + - name: Setup pnpm (corepack enabled) + uses: pnpm/action-setup@v3 + + - name: Setup Node.js 20.x + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4 + with: + node-version-file: '.node-version' + cache: 'pnpm' + + - name: Install Dependencies + run: pnpm ci:install + shell: bash + + - name: Create Translation Changesets + run: pnpm translations:changeset + env: + CI_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5 + with: + commit_message: '[ci] changesets' + branch: ${{ github.head_ref }} + commit_user_name: astrolicious + commit_user_email: no-reply@studiocms.xyz + commit_author: StudioCMS \ No newline at end of file diff --git a/README.md b/README.md index 1e13cea5c..e879a1d59 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,13 @@ To see how to get started, check out the [StudioCMS README](./packages/studiocms +## StudioCMS Dashboard i18n Status + +Translation status + ## Contributing -We welcome contributions from the community! Whether it's bug reports, feature requests, or code contributions, we appreciate your help in making this project better. To get started read our [Contributing Guide](https://docs.studiocms.xyz/start-here/contributing/) +We welcome contributions from the community! Whether it's bug reports, feature requests, or code contributions, we appreciate your help in making this project better. To get started read our [Contributing Guide](https://docs.studiocms.xyz/contributing/getting-started/) ## Chat with Us diff --git a/package.json b/package.json index 12cf9b2fc..69761c4ff 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "update:web": "pnpm --filter web up --latest", "update:docs": "pnpm --filter docs up --latest", "web:dev": "pnpm --filter web dev", - "docs:dev": "pnpm --filter docs dev" + "docs:dev": "pnpm --filter docs dev", + "translations:changeset": "tsm --require=./scripts/filter-warnings.cjs ./scripts/translation-changeset.ts" }, "devDependencies": { "@biomejs/biome": "1.9.3", @@ -35,6 +36,9 @@ "@changesets/cli": "2.27.9", "@changesets/config": "3.0.3", "@changesets/changelog-github": "^0.5.0", - "typescript": "catalog:" + "@changesets/write": "0.3.2", + "execa": "9.5.1", + "typescript": "catalog:", + "tsm": "2.3.0" } } diff --git a/packages/studiocms_auth/src/components/OAuthButtonStack.astro b/packages/studiocms_auth/src/components/OAuthButtonStack.astro index 731c4f205..bae54cdfc 100644 --- a/packages/studiocms_auth/src/components/OAuthButtonStack.astro +++ b/packages/studiocms_auth/src/components/OAuthButtonStack.astro @@ -1,12 +1,16 @@ --- +import { getLangFromUrl, useTranslations } from 'studiocms:i18n'; import { Divider } from '@studiocms/ui/components'; import OAuthButton from './OAuthButton.astro'; import { providerData, showOAuth } from './oAuthButtonProviders'; +const lang = getLangFromUrl(Astro.url); +const t = useTranslations(lang, '@studiocms/auth:oauth-stack'); + const shouldShowOAuth = showOAuth && providerData.some(({ enabled }) => enabled); --- { shouldShowOAuth && ( - or log in using + {t('or-login-with')}
{ providerData.map(({enabled, ...props}) => enabled && ) diff --git a/packages/studiocms_auth/src/components/StaticAuthCheck.astro b/packages/studiocms_auth/src/components/StaticAuthCheck.astro new file mode 100644 index 000000000..8452ea897 --- /dev/null +++ b/packages/studiocms_auth/src/components/StaticAuthCheck.astro @@ -0,0 +1,33 @@ +--- +import { getUserData } from 'studiocms:auth/lib/user'; +import { StudioCMSRoutes } from 'studiocms:helpers/routemap'; +import { getLangFromUrl, useTranslatedPath } from 'studiocms:i18n'; + +const { isLoggedIn } = await getUserData(Astro); +// Get the language and translations +const referer = Astro.request.headers.get('referer'); + +if (!referer) { + throw new Error('No referer found'); +} + +const lang = getLangFromUrl(new URL(referer)); +const translatePath = useTranslatedPath(lang); +const { + mainLinks: { dashboardIndex }, +} = StudioCMSRoutes; +--- + + + \ No newline at end of file diff --git a/packages/studiocms_auth/src/integration.ts b/packages/studiocms_auth/src/integration.ts index 9d2471ac6..a47d20298 100644 --- a/packages/studiocms_auth/src/integration.ts +++ b/packages/studiocms_auth/src/integration.ts @@ -83,6 +83,7 @@ export default defineIntegration({ }, experimental: { directRenderScript: true, + serverIslands: true, }, vite: { optimizeDeps: { @@ -112,6 +113,11 @@ export default defineIntegration({ entrypoint: resolve('./routes/api/login.ts'), enabled: usernameAndPasswordAPI, }, + { + pattern: 'logout', + entrypoint: resolve('./routes/api/logout.ts'), + enabled: dashboardEnabled && !options.dbStartPage, + }, { pattern: 'register', entrypoint: resolve('./routes/api/register.ts'), @@ -170,7 +176,7 @@ export default defineIntegration({ }, { pattern: 'logout/', - entrypoint: resolve('./routes/logout.ts'), + entrypoint: resolve('./routes/logout.astro'), enabled: dashboardEnabled && !options.dbStartPage, }, { diff --git a/packages/studiocms_auth/src/layouts/AuthLayout.astro b/packages/studiocms_auth/src/layouts/AuthLayout.astro index e378f984b..8d79a6927 100644 --- a/packages/studiocms_auth/src/layouts/AuthLayout.astro +++ b/packages/studiocms_auth/src/layouts/AuthLayout.astro @@ -21,10 +21,11 @@ const { interface Props { title: string; description: string; - lang?: string; + lang: string; + disableScreen?: boolean; } -const { title, description, lang = 'en' } = Astro.props; +const { title, description, lang, disableScreen } = Astro.props; // Get the site config const siteConfig = await db @@ -37,9 +38,10 @@ const siteConfig = await db const loginPageBackground = siteConfig?.loginPageBackground; const loginPageCustomImage = siteConfig?.loginPageCustomImage; -const fallbackImageSrc = loginPageBackground === 'custom' - ? loginPageCustomImage - : validImages.find((x) => x.name !== 'custom' && x.name === loginPageBackground)?.dark; // TODO: Adapt to theme +const fallbackImageSrc = + loginPageBackground === 'custom' + ? loginPageCustomImage + : validImages.find((x) => x.name !== 'custom' && x.name === loginPageBackground)?.dark; // TODO: Adapt to theme --- @@ -87,7 +89,7 @@ const fallbackImageSrc = loginPageBackground === 'custom' - + { !disableScreen && }