-
Notifications
You must be signed in to change notification settings - Fork 35
feat(vue): add lightweight Vue runtime #2012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 f9eaecb
fix(vue): preserve runtime extraction parity
eoinest fbb516b
fix(vue): normalize translated element children
eoinest 334de4a
chore(vue): normalize lockfile entries
eoinest a772f4c
refactor(vue): organize package sources
eoinest aee723f
docs(vue): mark package as unstable
eoinest 9e745b3
fix(vue): deduplicate branch names
eoinest b6d9e6a
fix(vue): use public vnode prop cloning
eoinest 18f0f28
refactor(vue): keep package sources under src
eoinest 9d478b1
test(vue): cover translated component props
eoinest 5a4359b
refactor(i18n): share string message helpers
eoinest eb92fd1
refactor(i18n): call hashSource directly for string messages
eoinest 76380b5
refactor(i18n): share literal string hashing
eoinest c755b2c
fix(vue): harden runtime release contracts
eoinest 4cdb5c2
fix(vue): suppress variable fallthrough attrs
eoinest 4e01819
fix(vue): preserve translated vnode semantics
eoinest 40905c6
fix(vue): preserve keyed fragment identity
eoinest 2a72169
fix(vue): render text Suspense roots
eoinest bf0c006
fix(vue): stabilize translated Suspense roots
eoinest 277452c
docs(vue): document opaque slot boundaries
eoinest 74f5a40
fix(vue): serialize Fragment default slots
eoinest 2ab4c07
fix(vue): enforce runtime release contracts
eoinest a9a5e3e
chore(vue): test on maintained Node
eoinest a5f3871
fix(vue): align rich formatter locales
eoinest ffe5951
fix(vue): keep formatter locale override private
eoinest 5e59882
fix(vue): bound reconciliation identities
eoinest f00d89e
chore(i18n): release string helpers as patch
eoinest 8184c2f
fix(vue): persist locale in browser cookie
eoinest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); | ||
| } |
16 changes: 16 additions & 0 deletions
16
packages/i18n/src/translation-functions/utils/__tests__/isEncodedTranslationOptions.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.