Skip to content

Commit 1fc1837

Browse files
committed
fix: replace t_with_fallback with utility.translate
1 parent 23e3302 commit 1fc1837

7 files changed

Lines changed: 31 additions & 31 deletions

File tree

src/utilities/locales.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ function extractStorefrontTranslationKeys(content: string): Set<string> {
148148
}
149149
}
150150

151-
// Combine with t_with_fallback translations
152-
return new Set([...keys, ...extractTWithFallbackTranslationKeys(content)])
151+
// Combine with utility.translate translations
152+
return new Set([...keys, ...extractUtilityTranslateKeys(content)])
153153
}
154154

155-
function extractTWithFallbackTranslationKeys(content: string): Set<string> {
155+
function extractUtilityTranslateKeys(content: string): Set<string> {
156156
// Find translations assigned to variables first
157157
const assignedTranslations = findTranslationVariables(content)
158158

159159
// Find both direct keys and variable-based keys
160-
const directKeys = extractDirectTWithFallbackTranslationKeys(content)
161-
const variableKeys = extractVariableTWithFallbackTranslationKeys(content, assignedTranslations)
160+
const directKeys = extractDirectUtilityTranslateKeys(content)
161+
const variableKeys = extractVariableUtilityTranslateKeys(content, assignedTranslations)
162162

163163
return new Set([...directKeys, ...variableKeys])
164164
}
@@ -176,9 +176,9 @@ function findTranslationVariables(content: string): Map<string, string> {
176176
return assignments
177177
}
178178

179-
function extractDirectTWithFallbackTranslationKeys(content: string): Set<string> {
179+
function extractDirectUtilityTranslateKeys(content: string): Set<string> {
180180
const keys = new Set<string>()
181-
const pattern = /render\s+["']t_with_fallback["'][^%]*key:\s*["']([^"']+)["']/g
181+
const pattern = /render\s+["']utility.translate["'][^%]*key:\s*["']([^"']+)["']/g
182182

183183
const matches = [...content.matchAll(pattern)]
184184
for (const match of matches) {
@@ -188,9 +188,9 @@ function extractDirectTWithFallbackTranslationKeys(content: string): Set<string>
188188
return keys
189189
}
190190

191-
function extractVariableTWithFallbackTranslationKeys(content: string, assignedTranslations: Map<string, string>): Set<string> {
191+
function extractVariableUtilityTranslateKeys(content: string, assignedTranslations: Map<string, string>): Set<string> {
192192
const keys = new Set<string>()
193-
const pattern = /render\s+["']t_with_fallback["'][^%]*t:\s*([^\s,}]+)/g
193+
const pattern = /render\s+["']utility.translate["'][^%]*t:\s*([^\s,}]+)/g
194194

195195
const matches = [...content.matchAll(pattern)]
196196
for (const match of matches) {

test/commands/theme/locale/clean.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ describe('theme locale clean', () => {
6767

6868
const storefrontContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'en.default.json'), 'utf8'))
6969
expect(storefrontContent).to.have.nested.property('actions.add_to_cart')
70-
expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key')
71-
expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key')
70+
expect(storefrontContent).to.have.nested.property('translate.direct_key')
71+
expect(storefrontContent).to.have.nested.property('translate.variable_key')
7272

7373
const schemaContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'en.default.schema.json'), 'utf8'))
7474
expect(schemaContent).to.have.nested.property('section.name')

test/commands/theme/locale/sync.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ describe('theme locale sync', () => {
3434

3535
const storefrontContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'en.default.json'), 'utf8'))
3636
expect(storefrontContent).to.have.nested.property('actions.add_to_cart')
37-
expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key')
38-
expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key')
37+
expect(storefrontContent).to.have.nested.property('translate.direct_key')
38+
expect(storefrontContent).to.have.nested.property('translate.variable_key')
3939

4040
const frStorefrontContent = JSON.parse(fs.readFileSync(path.join(testThemeLocalesPath, 'fr.json'), 'utf8'))
4141
expect(frStorefrontContent).to.have.nested.property('actions.add_to_cart')
42-
expect(frStorefrontContent).to.have.nested.property('t_with_fallback.direct_key')
43-
expect(frStorefrontContent).to.have.nested.property('t_with_fallback.variable_key')
42+
expect(frStorefrontContent).to.have.nested.property('translate.direct_key')
43+
expect(frStorefrontContent).to.have.nested.property('translate.variable_key')
4444

4545
expect(frStorefrontContent.actions.add_to_cart).to.equal(sourceFr.actions.add_to_cart)
4646
})
@@ -136,8 +136,8 @@ describe('theme locale sync', () => {
136136
expect(storefrontContent).to.not.have.property('unused')
137137

138138
expect(storefrontContent).to.have.nested.property('actions.add_to_cart')
139-
expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key')
140-
expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key')
139+
expect(storefrontContent).to.have.nested.property('translate.direct_key')
140+
expect(storefrontContent).to.have.nested.property('translate.variable_key')
141141
})
142142

143143
it('syncs schema files with add-and-override mode', async () => {
@@ -170,8 +170,8 @@ describe('theme locale sync', () => {
170170
expect(schemaContent).to.not.have.nested.property('additional.new_setting')
171171

172172
expect(storefrontContent).to.have.nested.property('actions.add_to_cart')
173-
expect(storefrontContent).to.have.nested.property('t_with_fallback.direct_key')
174-
expect(storefrontContent).to.have.nested.property('t_with_fallback.variable_key')
173+
expect(storefrontContent).to.have.nested.property('translate.direct_key')
174+
expect(storefrontContent).to.have.nested.property('translate.variable_key')
175175
expect(schemaContent).to.have.nested.property('section.name')
176176
expect(schemaContent).to.have.nested.property('section.settings.logo_label')
177177
})

test/fixtures/locales/en.default.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"additional": {
66
"new_key": "This is a new translation (source)"
77
},
8-
"t_with_fallback": {
9-
"direct_key": "Direct key (source)",
10-
"variable_key": "Variable key (source)"
11-
},
128
"tags": {
139
"new": "New",
1410
"sale": "Sale",
1511
"featured": "Featured",
1612
"custom": "Custom Tag",
1713
"special": "Special Tag"
14+
},
15+
"translate": {
16+
"direct_key": "Direct key (source)",
17+
"variable_key": "Variable key (source)"
1818
}
1919
}

test/fixtures/locales/fr.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"additional": {
66
"new_key": "Ceci est une nouvelle traduction (source)"
77
},
8-
"t_with_fallback": {
9-
"direct_key": "Clé directe (source)",
10-
"variable_key": "Clé variable (source)"
11-
},
128
"tags": {
139
"new": "Nouveau",
1410
"sale": "En solde",
1511
"featured": "En vedette",
1612
"custom": "Personnalisée",
1713
"special": "Spéciale"
14+
},
15+
"translate": {
16+
"direct_key": "Clé directe (source)",
17+
"variable_key": "Clé variable (source)"
1818
}
1919
}

test/fixtures/theme/locales/en.default.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"actions": {
33
"add_to_cart": "Add to cart"
44
},
5-
"t_with_fallback": {
5+
"translate": {
66
"direct_key": "Direct key",
77
"variable_key": "Variable key"
88
},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{%- assign translation_key = 't_with_fallback.variable_key' | t -%}
2-
{%- render 't_with_fallback', t: translation_key -%}
3-
{%- render 't_with_fallback', key: 't_with_fallback.direct_key' -%}
1+
{%- assign translation_key = 'translate.variable_key' | t -%}
2+
{%- render 'utility.translate', t: translation_key -%}
3+
{%- render 'utility.translate', key: 'translate.direct_key' -%}

0 commit comments

Comments
 (0)