diff --git a/src/utilities/locales.ts b/src/utilities/locales.ts index aa8c294..9db8807 100644 --- a/src/utilities/locales.ts +++ b/src/utilities/locales.ts @@ -148,17 +148,17 @@ function extractStorefrontTranslationKeys(content: string): Set { } } - // Combine with t_with_fallback translations - return new Set([...keys, ...extractTWithFallbackTranslationKeys(content)]) + // Combine with utility.translate translations + return new Set([...keys, ...extractUtilityTranslateKeys(content)]) } -function extractTWithFallbackTranslationKeys(content: string): Set { +function extractUtilityTranslateKeys(content: string): Set { // Find translations assigned to variables first const assignedTranslations = findTranslationVariables(content) // Find both direct keys and variable-based keys - const directKeys = extractDirectTWithFallbackTranslationKeys(content) - const variableKeys = extractVariableTWithFallbackTranslationKeys(content, assignedTranslations) + const directKeys = extractDirectUtilityTranslateKeys(content) + const variableKeys = extractVariableUtilityTranslateKeys(content, assignedTranslations) return new Set([...directKeys, ...variableKeys]) } @@ -176,9 +176,9 @@ function findTranslationVariables(content: string): Map { return assignments } -function extractDirectTWithFallbackTranslationKeys(content: string): Set { +function extractDirectUtilityTranslateKeys(content: string): Set { const keys = new Set() - const pattern = /render\s+["']t_with_fallback["'][^%]*key:\s*["']([^"']+)["']/g + const pattern = /render\s+["']utility.translate["'][^%]*key:\s*["']([^"']+)["']/g const matches = [...content.matchAll(pattern)] for (const match of matches) { @@ -188,9 +188,9 @@ function extractDirectTWithFallbackTranslationKeys(content: string): Set return keys } -function extractVariableTWithFallbackTranslationKeys(content: string, assignedTranslations: Map): Set { +function extractVariableUtilityTranslateKeys(content: string, assignedTranslations: Map): Set { const keys = new Set() - const pattern = /render\s+["']t_with_fallback["'][^%]*t:\s*([^\s,}]+)/g + const pattern = /render\s+["']utility.translate["'][^%]*t:\s*([^\s,}]+)/g const matches = [...content.matchAll(pattern)] for (const match of matches) { diff --git a/test/commands/theme/locale/clean.test.ts b/test/commands/theme/locale/clean.test.ts index 746dcc6..f8f828d 100644 --- a/test/commands/theme/locale/clean.test.ts +++ b/test/commands/theme/locale/clean.test.ts @@ -67,8 +67,8 @@ describe('theme locale clean', () => { const storefrontContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'en.default.json'), 'utf8')) expect(storefrontContent).to.have.nested.property('actions.add_to_cart') - expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key') - expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key') + expect(storefrontContent).to.have.nested.property('translate.direct_key') + expect(storefrontContent).to.have.nested.property('translate.variable_key') const schemaContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'en.default.schema.json'), 'utf8')) expect(schemaContent).to.have.nested.property('section.name') diff --git a/test/commands/theme/locale/sync.test.ts b/test/commands/theme/locale/sync.test.ts index e00e96b..6f8849e 100644 --- a/test/commands/theme/locale/sync.test.ts +++ b/test/commands/theme/locale/sync.test.ts @@ -34,13 +34,13 @@ describe('theme locale sync', () => { const storefrontContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'en.default.json'), 'utf8')) expect(storefrontContent).to.have.nested.property('actions.add_to_cart') - expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key') - expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key') + expect(storefrontContent).to.have.nested.property('translate.direct_key') + expect(storefrontContent).to.have.nested.property('translate.variable_key') const frStorefrontContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'fr.json'), 'utf8')) expect(frStorefrontContent).to.have.nested.property('actions.add_to_cart') - expect(frStorefrontContent).to.have.nested.property('t_with_fallback.direct_key') - expect(frStorefrontContent).to.have.nested.property('t_with_fallback.variable_key') + expect(frStorefrontContent).to.have.nested.property('translate.direct_key') + expect(frStorefrontContent).to.have.nested.property('translate.variable_key') expect(frStorefrontContent.actions.add_to_cart).to.equal(sourceFr.actions.add_to_cart) }) @@ -136,8 +136,8 @@ describe('theme locale sync', () => { expect(storefrontContent).to.not.have.property('unused') expect(storefrontContent).to.have.nested.property('actions.add_to_cart') - expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key') - expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key') + expect(storefrontContent).to.have.nested.property('translate.direct_key') + expect(storefrontContent).to.have.nested.property('translate.variable_key') }) it('syncs schema files with add-and-override mode', async () => { @@ -170,8 +170,8 @@ describe('theme locale sync', () => { expect(schemaContent).to.not.have.nested.property('additional.new_setting') expect(storefrontContent).to.have.nested.property('actions.add_to_cart') - expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key') - expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key') + expect(storefrontContent).to.have.nested.property('translate.direct_key') + expect(storefrontContent).to.have.nested.property('translate.variable_key') expect(schemaContent).to.have.nested.property('section.name') expect(schemaContent).to.have.nested.property('section.settings.logo_label') }) diff --git a/test/fixtures/locales/en.default.json b/test/fixtures/locales/en.default.json index 329174a..71375d1 100644 --- a/test/fixtures/locales/en.default.json +++ b/test/fixtures/locales/en.default.json @@ -5,15 +5,15 @@ "additional": { "new_key": "This is a new translation (source)" }, - "t_with_fallback": { - "direct_key": "Direct key (source)", - "variable_key": "Variable key (source)" - }, "tags": { "new": "New", "sale": "Sale", "featured": "Featured", "custom": "Custom Tag", "special": "Special Tag" + }, + "translate": { + "direct_key": "Direct key (source)", + "variable_key": "Variable key (source)" } } diff --git a/test/fixtures/locales/fr.json b/test/fixtures/locales/fr.json index 030c44a..a15e228 100644 --- a/test/fixtures/locales/fr.json +++ b/test/fixtures/locales/fr.json @@ -5,15 +5,15 @@ "additional": { "new_key": "Ceci est une nouvelle traduction (source)" }, - "t_with_fallback": { - "direct_key": "Clé directe (source)", - "variable_key": "Clé variable (source)" - }, "tags": { "new": "Nouveau", "sale": "En solde", "featured": "En vedette", "custom": "Personnalisée", "special": "Spéciale" + }, + "translate": { + "direct_key": "Clé directe (source)", + "variable_key": "Clé variable (source)" } } diff --git a/test/fixtures/theme/locales/en.default.json b/test/fixtures/theme/locales/en.default.json index 23c96b7..6f436ca 100644 --- a/test/fixtures/theme/locales/en.default.json +++ b/test/fixtures/theme/locales/en.default.json @@ -2,7 +2,7 @@ "actions": { "add_to_cart": "Add to cart" }, - "t_with_fallback": { + "translate": { "direct_key": "Direct key", "variable_key": "Variable key" }, diff --git a/test/fixtures/theme/snippets/t-with-fallback-usage.liquid b/test/fixtures/theme/snippets/t-with-fallback-usage.liquid index e8d9b73..1bd4398 100644 --- a/test/fixtures/theme/snippets/t-with-fallback-usage.liquid +++ b/test/fixtures/theme/snippets/t-with-fallback-usage.liquid @@ -1,3 +1,3 @@ -{%- assign translation_key = 't_with_fallback.variable_key' | t -%} -{%- render 't_with_fallback', t: translation_key -%} -{%- render 't_with_fallback', key: 't_with_fallback.direct_key' -%} +{%- assign translation_key = 'translate.variable_key' | t -%} +{%- render 'utility.translate', t: translation_key -%} +{%- render 'utility.translate', key: 'translate.direct_key' -%}