Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
"auth_company_name_placeholder": "Acme Corp",
"auth_required_agreements_label": "必須同意事項 *",
"auth_agree_to": "",
"auth_terms_of_service": "利用規約に同意する",
"auth_terms_of_service": "クッキーポリシーに同意する",
"auth_privacy_policy": "プライバシーポリシーに同意する",
"auth_cookie_policy": "Cookie ポリシーに同意する",
"auth_eula": "エンドユーザー使用許諾契約に同意する",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/auth/LegalConsentFields.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { m } from '$lib/paraglide/messages.js';
import { legalDocumentUrl } from '$lib/i18n/legal-urls';

interface Props {
agreedPrivacy: boolean;
Expand All @@ -16,9 +17,9 @@
agreedTerms = $bindable(false),
agreedEula = $bindable(false),
allConsentsGiven,
privacyUrl = 'https://www.cropwatch.io/legal/privacy-policy',
termsUrl = 'https://www.cropwatch.io/legal/terms-of-service',
eulaUrl = 'https://www.cropwatch.io/legal/EULA'
privacyUrl = legalDocumentUrl('privacy_policy'),
termsUrl = legalDocumentUrl('terms_of_service'),
eulaUrl = legalDocumentUrl('eula')
}: Props = $props();

// The matching checkbox stays disabled until its policy link has been opened.
Expand Down
24 changes: 24 additions & 0 deletions src/lib/i18n/legal-urls.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { legalDocumentUrl } from './legal-urls';

describe('legalDocumentUrl', () => {
it('links English users to the global site', () => {
expect(legalDocumentUrl('privacy_policy', 'en')).toBe(
'https://www.cropwatch.io/legal/privacy-policy'
);
expect(legalDocumentUrl('terms_of_service', 'en')).toBe(
'https://www.cropwatch.io/legal/terms-of-service'
);
expect(legalDocumentUrl('eula', 'en')).toBe('https://www.cropwatch.io/legal/EULA');
});

it('links Japanese users directly to the Japanese site so the geo redirect cannot drop the path', () => {
expect(legalDocumentUrl('privacy_policy', 'ja')).toBe(
'https://cropwatch.co.jp/legal/privacy-policy'
);
expect(legalDocumentUrl('terms_of_service', 'ja')).toBe(
'https://cropwatch.co.jp/legal/terms-of-service'
);
expect(legalDocumentUrl('eula', 'ja')).toBe('https://cropwatch.co.jp/legal/EULA');
});
});
26 changes: 26 additions & 0 deletions src/lib/i18n/legal-urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { LegalDocumentKind } from '$lib/api/api.dtos';
import { getLocale } from '$lib/paraglide/runtime';
import { getUiLocale } from './format';

// Canonical hosts: cropwatch.io redirects to www, cropwatch.co.jp redirects www away.
const LEGAL_SITE_ORIGIN = {
en: 'https://www.cropwatch.io',
ja: 'https://cropwatch.co.jp'
} as const;

const LEGAL_DOCUMENT_PATH: Record<LegalDocumentKind, string> = {
privacy_policy: '/legal/privacy-policy',
terms_of_service: '/legal/terms-of-service',
eula: '/legal/EULA'
};

/**
* Public URL of a legal document on the marketing site that matches the UI locale.
*
* cropwatch.io geo-redirects visitors in Japan to the cropwatch.co.jp *home page*
* (the path is dropped), so Japanese-locale users must be linked straight to
* cropwatch.co.jp to land on the document they are agreeing to.
*/
export function legalDocumentUrl(kind: LegalDocumentKind, locale = getLocale()): string {
return `${LEGAL_SITE_ORIGIN[getUiLocale(locale)]}${LEGAL_DOCUMENT_PATH[kind]}`;
}
Loading