Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ae74a29
feat(vue): add lightweight Vue runtime
eoinest Jul 31, 2026
f9eaecb
fix(vue): preserve runtime extraction parity
eoinest Jul 31, 2026
fbb516b
fix(vue): normalize translated element children
eoinest Jul 31, 2026
334de4a
chore(vue): normalize lockfile entries
eoinest Jul 31, 2026
a772f4c
refactor(vue): organize package sources
eoinest Jul 31, 2026
aee723f
docs(vue): mark package as unstable
eoinest Jul 31, 2026
9e745b3
fix(vue): deduplicate branch names
eoinest Jul 31, 2026
b6d9e6a
fix(vue): use public vnode prop cloning
eoinest Jul 31, 2026
18f0f28
refactor(vue): keep package sources under src
eoinest Jul 31, 2026
9d478b1
test(vue): cover translated component props
eoinest Jul 31, 2026
5a4359b
refactor(i18n): share string message helpers
eoinest Jul 31, 2026
eb92fd1
refactor(i18n): call hashSource directly for string messages
eoinest Jul 31, 2026
76380b5
refactor(i18n): share literal string hashing
eoinest Aug 1, 2026
c755b2c
fix(vue): harden runtime release contracts
eoinest Aug 1, 2026
4cdb5c2
fix(vue): suppress variable fallthrough attrs
eoinest Aug 1, 2026
4e01819
fix(vue): preserve translated vnode semantics
eoinest Aug 5, 2026
40905c6
fix(vue): preserve keyed fragment identity
eoinest Aug 5, 2026
2a72169
fix(vue): render text Suspense roots
eoinest Aug 5, 2026
bf0c006
fix(vue): stabilize translated Suspense roots
eoinest Aug 5, 2026
277452c
docs(vue): document opaque slot boundaries
eoinest Aug 5, 2026
74f5a40
fix(vue): serialize Fragment default slots
eoinest Aug 5, 2026
2ab4c07
fix(vue): enforce runtime release contracts
eoinest Aug 5, 2026
a9a5e3e
chore(vue): test on maintained Node
eoinest Aug 5, 2026
a5f3871
fix(vue): align rich formatter locales
eoinest Aug 5, 2026
ffe5951
fix(vue): keep formatter locale override private
eoinest Aug 5, 2026
5e59882
fix(vue): bound reconciliation identities
eoinest Aug 6, 2026
f00d89e
chore(i18n): release string helpers as patch
eoinest Aug 6, 2026
8184c2f
fix(vue): persist locale in browser cookie
eoinest Aug 6, 2026
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
9 changes: 9 additions & 0 deletions .changeset/calm-pandas-translate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'gt-vue': minor
---

Add a lightweight Vue 3 runtime with catalog-backed string and rich-content
translation, cookie-backed reactive locale switching, child-only variables,
and typed value props for number, currency, and date formatting. Browser SPAs
restore the locale from a configurable cookie, while an explicit server locale
wins during SSR hydration.
10 changes: 10 additions & 0 deletions .changeset/tidy-vue-messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'gt-i18n': patch
---

Make `msg(..., { $format: 'STRING' })` preserve source text literally instead
of applying ICU interpolation. For example, `msg('Hello {name}', {
$format: 'STRING', name: 'Ada' })` now encodes `Hello {name}` rather than
`Hello Ada`. Add lightweight shared helpers for registering, hashing, and
decoding literal STRING messages, browser cookie access, and canonical GT
cookie names, and validate encoded fields by type.
2 changes: 1 addition & 1 deletion .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Turbo tasks: `build`, `test`, `lint`, `lint:fix`, `format`, `format:fix`, `trans
- Never repeat a library fallback as a literal in production source. Import the canonical constant so a default change propagates across every package. Before adding a fallback, search the owning package's settings and constants modules for an existing default.
- The canonical locale is `libraryDefaultLocale`. Inside `packages/core`, import it from `src/settings/settings.ts`; inside `packages/format`, import its local copy from `src/settings/settings.ts` because core depends on format; everywhere else, import it from `generaltranslation/internal`.
- Core's canonical request timeout is `defaultTimeout` in `packages/core/src/settings/settings.ts`. Its service endpoints are `defaultBaseUrl`, `defaultCacheUrl`, and `defaultRuntimeApiUrl` in `packages/core/src/settings/settingsUrls.ts`; other packages consume the endpoint defaults from `generaltranslation/internal`.
- The canonical locale, region, feature-flag, and reset cookie names live in `packages/react-core/src/setup/cookieNames.ts` and are available from `@generaltranslation/react-core/pure`. The Next.js routing cookie and locale header defaults live in `packages/next/src/utils/cookies.ts` and `packages/next/src/utils/headers.ts`; gt-next source should import those constants instead of repeating their values.
- The canonical locale, region, feature-flag, and reset cookie names live in `packages/i18n/src/utils/cookieNames.ts` and are available from `gt-i18n/internal/cookies`; React integrations also re-export them from `@generaltranslation/react-core/pure` for compatibility. The Next.js routing cookie and locale header defaults live in `packages/next/src/utils/cookies.ts` and `packages/next/src/utils/headers.ts`; gt-next source should import those constants instead of repeating their values.
- `packages/core` and `packages/format` intentionally define matching locale and timeout defaults to preserve their dependency direction. Keep the copies synchronized.
- Tests, fixtures, examples, and documentation may use explicit values when the value itself matters to the scenario. Prefer canonical constants when testing default behavior.
- Run `pnpm check:library-defaults` after changing a canonical default or adding fallback behavior. If a literal matches a canonical value but has a distinct meaning, add only a narrow, documented exception to `scripts/check-library-defaults.mjs`.
Expand Down
50 changes: 49 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,53 @@ jobs:
pnpm exec turbo build --filter=general-cases... --force
pnpm exec turbo build:turbopack --filter=general-cases... --force

test-vue-versions:
strategy:
matrix:
vue: ['3.3.13', '3.5.40']
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if gt-vue changed
id: gt_vue_changed
shell: bash
run: |
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "^packages/vue/"; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi

- uses: pnpm/action-setup@v4
if: steps.gt_vue_changed.outputs.changed == 'true'
name: Install pnpm

- name: Setup Node.js
if: steps.gt_vue_changed.outputs.changed == 'true'
uses: actions/setup-node@v4
with:
node-version: 24
cache: 'pnpm'

- name: Install dependencies
if: steps.gt_vue_changed.outputs.changed == 'true'
run: pnpm install

- name: Use Vue ${{ matrix.vue }}
if: steps.gt_vue_changed.outputs.changed == 'true'
run: pnpm --filter gt-vue add --save-dev --save-exact --lockfile=false vue@${{ matrix.vue }}

- name: Build and test gt-vue
if: steps.gt_vue_changed.outputs.changed == 'true'
run: |
pnpm exec turbo build --filter=gt-vue...
pnpm --filter gt-vue typecheck
pnpm --filter gt-vue test

test-cli-binaries:
strategy:
matrix:
Expand Down Expand Up @@ -279,7 +326,8 @@ jobs:
script: pnpm exec size-limit --json

run-tests:
needs: [lint, tests, test-builds, test-cli-binaries, size]
needs:
[lint, tests, test-builds, test-vue-versions, test-cli-binaries, size]
runs-on: ubuntu-latest
steps:
- run: echo "All tests passed"
9 changes: 9 additions & 0 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const react = (name, file, limit = '50 kB') =>
ignore: reactPeerIgnore,
});

const vue = (name, file, limit = '15 kB') =>
entry(name, `packages/vue/dist/${file}.mjs`, limit, {
ignore: ['vue'],
});

const reactNode = (name, file, limit = '50 kB') =>
nodeEntry(name, `packages/react/dist/${file}.mjs`, limit, {
ignore: reactPeerIgnore,
Expand Down Expand Up @@ -91,6 +96,8 @@ module.exports = [
i18n('gt-i18n', 'index'),
i18n('gt-i18n/types', 'types'),
i18n('gt-i18n/internal', 'internal'),
i18n('gt-i18n/internal/cookies', 'internal-cookies'),
i18n('gt-i18n/internal/string', 'internal-string'),
i18n('gt-i18n/internal/types', 'internal-types'),

reactCore('@generaltranslation/react-core/pure', 'pure'),
Expand All @@ -103,6 +110,8 @@ module.exports = [
reactNode('gt-react (server)', 'index.server', '55 kB'),
react('gt-react/macros', 'macros'),

vue('gt-vue', 'index'),

next('gt-next (client)', 'index.client', '75 kB'),
nextNode('gt-next (rsc)', 'index.rsc', '85 kB'),
nextNode('gt-next (server)', 'index.server', '85 kB'),
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Visit [https://generaltranslation.com/docs](https://generaltranslation.com/docs)
| ------------------------------------------------------------------- | ------------------------------------------------- |
| [gt-next](packages/next) | Automatic i18n for Next.js |
| [gt-react](packages/react) | Automatic i18n for React |
| [gt-vue](packages/vue) | Lightweight i18n for Vue |
| [gt-i18n](packages/i18n) | Pure JavaScript i18n library |
| [gt](packages/cli) | CLI tool for continuous localization |
| [gt-sanity](packages/sanity) | Plugin for Sanity Studio v3 |
Expand Down
26 changes: 26 additions & 0 deletions packages/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@
"default": "./dist/internal.mjs"
}
},
"./internal/cookies": {
"require": {
"types": "./dist/internal-cookies.d.cts",
"default": "./dist/internal-cookies.cjs"
},
"import": {
"types": "./dist/internal-cookies.d.mts",
"default": "./dist/internal-cookies.mjs"
}
},
"./internal/string": {
"require": {
"types": "./dist/internal-string.d.cts",
"default": "./dist/internal-string.cjs"
},
"import": {
"types": "./dist/internal-string.d.mts",
"default": "./dist/internal-string.mjs"
}
},
"./internal/types": {
"require": {
"types": "./dist/internal-types.d.cts",
Expand All @@ -105,6 +125,12 @@
"internal": [
"./dist/internal.d.cts"
],
"internal/cookies": [
"./dist/internal-cookies.d.cts"
],
"internal/string": [
"./dist/internal-string.d.cts"
],
"internal/types": [
"./dist/internal-types.d.cts"
]
Expand Down
11 changes: 11 additions & 0 deletions packages/i18n/src/internal-cookies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export {
defaultEnableI18nCookieName,
defaultLocaleCookieName,
defaultRegionCookieName,
defaultResetLocaleCookieName,
} from './utils/cookieNames';
export {
getBrowserCookieValue,
setBrowserCookieValue,
} from './utils/browserCookies';
export { getCookieValue } from './utils/request';
4 changes: 4 additions & 0 deletions packages/i18n/src/internal-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { decodeOptions } from './translation-functions/msg/decodeOptions';
export { msgString } from './translation-functions/msg/msgString';
export { isEncodedTranslationOptions } from './translation-functions/utils/isEncodedTranslationOptions';
export { hashStringMessage } from './utils/hashStringMessage';
15 changes: 15 additions & 0 deletions packages/i18n/src/translation-functions/msg/__tests__/msg.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { msg } from '../msg';
import { decodeMsg } from '../decodeMsg';
import { decodeOptions } from '../decodeOptions';
import { derive, declareVar } from 'generaltranslation/internal';
import type { RegisterableMessages } from '../../types/message';

Expand All @@ -17,6 +18,20 @@ describe('msg function integration', () => {
expect(decoded).toBe('Hello World');
});

it('preserves literal braces for STRING messages', () => {
const result = msg('Hello {name}', {
$context: 'literal example',
$format: 'STRING',
});

expect(decodeMsg(result)).toBe('Hello {name}');
expect(decodeOptions(result)).toMatchObject({
$context: 'literal example',
$format: 'STRING',
$_source: 'Hello {name}',
});
});

it('should not format variables in quoted text', () => {
const result = msg("'Hello {name}'");
const decoded = decodeMsg(result);
Expand Down
10 changes: 10 additions & 0 deletions packages/i18n/src/translation-functions/msg/encodeMsg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { encode } from 'generaltranslation/internal';
import type { EncodedTranslationOptions } from '../types/options';

/** Encodes message metadata for later resolution by an `m` function. */
export function encodeMsg(
message: string,
options: EncodedTranslationOptions
): string {
return `${message}:${encode(JSON.stringify(options))}`;
}
15 changes: 6 additions & 9 deletions packages/i18n/src/translation-functions/msg/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
} from '../types/options';
import { formatMessage } from '@generaltranslation/format';
import {
encode,
libraryDefaultLocale,
VAR_IDENTIFIER,
} from 'generaltranslation/internal';
Expand All @@ -13,6 +12,8 @@ import logger from '../../logs/logger';
import { extractVariables } from '../../utils/extractVariables';
import { hashMessage } from '../../utils/hashMessage';
import { RegisterableMessages } from '../types/message';
import { encodeMsg } from './encodeMsg';
import { msgString } from './msgString';

/**
* Registers a message to be translated. Returns the message unchanged if no options are provided.
Expand Down Expand Up @@ -57,6 +58,8 @@ export function msg(
message: RegisterableMessages,
options?: GTTranslationOptions
): RegisterableMessages {
if (options?.$format === 'STRING') return msgString(message, options);
Comment thread
eoinest marked this conversation as resolved.

// Handle array
if (typeof message !== 'string') {
if (!options) return message;
Expand All @@ -73,11 +76,8 @@ export function msg(
return message;
}

// Extract variables
const variables = extractVariables(options);

// Interpolate string
let interpolatedString: string = message;
let interpolatedString: string;
try {
interpolatedString = formatMessage(message, {
locales: [libraryDefaultLocale], // TODO: use compiler to insert locales
Expand Down Expand Up @@ -105,8 +105,5 @@ export function msg(
$_source,
$_hash,
};
const optionsEncoding = encode(JSON.stringify(encodedOptions));

// Construct result
return `${interpolatedString}:${optionsEncoding}`;
return encodeMsg(interpolatedString, encodedOptions);
}
42 changes: 42 additions & 0 deletions packages/i18n/src/translation-functions/msg/msgString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { GTTranslationOptions } from '../types/options';
import type { RegisterableMessages } from '../types/message';
import { hashStringMessage } from '../../utils/hashStringMessage';
import { encodeMsg } from './encodeMsg';

/**
* Registers one or more literal STRING messages without applying ICU
* interpolation.
*
* Framework integrations should narrow the options they expose in their
* public API.
*/
export function msgString<T extends RegisterableMessages = string>(
message: T
): T;
export function msgString<T extends RegisterableMessages = string>(
message: T,
options?: GTTranslationOptions
): T extends string ? string : string[];
export function msgString(
message: RegisterableMessages,
options?: GTTranslationOptions
): RegisterableMessages {
if (typeof message !== 'string') {
if (!options) return message;
return message.map((entry, index) =>
msgString(entry, {
...options,
...(options.$id && { $id: `${options.$id}.${index}` }),
})
);
}
if (!options) return message;

const stringOptions = { ...options, $format: 'STRING' as const };
const $_hash = hashStringMessage(message, stringOptions);
return encodeMsg(message, {
...stringOptions,
$_hash,
$_source: message,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { isEncodedTranslationOptions } from '../isEncodedTranslationOptions';

describe('isEncodedTranslationOptions', () => {
it('accepts encoded empty source strings', () => {
expect(isEncodedTranslationOptions({ $_hash: 'hash', $_source: '' })).toBe(
true
);
});

it('rejects non-string encoded fields', () => {
expect(isEncodedTranslationOptions({ $_hash: {}, $_source: {} })).toBe(
false
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ import { EncodedTranslationOptions } from '../types/options';
export function isEncodedTranslationOptions(
decodedOptions: Record<string, unknown> // TODO: next major version, this should be Record<string, string>
): decodedOptions is EncodedTranslationOptions {
return !!(decodedOptions.$_hash && decodedOptions.$_source);
return (
typeof decodedOptions.$_hash === 'string' &&
typeof decodedOptions.$_source === 'string'
);
}
51 changes: 51 additions & 0 deletions packages/i18n/src/utils/__tests__/browserCookies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import {
getBrowserCookieValue,
setBrowserCookieValue,
} from '../browserCookies';
import {
defaultEnableI18nCookieName,
defaultLocaleCookieName,
defaultRegionCookieName,
defaultResetLocaleCookieName,
} from '../cookieNames';

describe('browser cookies', () => {
afterEach(() => vi.unstubAllGlobals());

it('keeps the canonical GT cookie names in one dependency-free module', () => {
expect(defaultLocaleCookieName).toBe('generaltranslation.locale');
expect(defaultRegionCookieName).toBe('generaltranslation.region');
expect(defaultEnableI18nCookieName).toBe('generaltranslation.enable-i18n');
expect(defaultResetLocaleCookieName).toBe(
'generaltranslation.locale-reset'
);
});

it('reads and decodes an exact browser cookie name', () => {
vi.stubGlobal('document', {
cookie:
'other=value; generaltranslation.locale=brand%2Dfrench%3Dca; generaltranslation.locale-extra=es',
});

expect(getBrowserCookieValue(defaultLocaleCookieName)).toBe(
'brand-french=ca'
);
});

it('writes the path-wide session-cookie contract used by GT web runtimes', () => {
const cookieDocument = { cookie: '' };
vi.stubGlobal('document', cookieDocument);

setBrowserCookieValue('custom-locale', 'fr-CA');

expect(cookieDocument.cookie).toBe('custom-locale=fr-CA;path=/');
});

it('does not access browser globals during SSR', () => {
expect(getBrowserCookieValue(defaultLocaleCookieName)).toBeUndefined();
expect(() =>
setBrowserCookieValue(defaultLocaleCookieName, 'fr')
).not.toThrow();
});
});
Loading
Loading