Skip to content

Commit ba4dd41

Browse files
Added translated flag to ctx
1 parent 7520ece commit ba4dd41

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Clients } from './clients'
66
import { schemaDirectives } from './directives'
77
import { resolvers } from './resolvers'
88
import {
9-
setWorkspaceSearchParams,
109
getWorkspaceSearchParams,
10+
setWorkspaceSearchParams,
1111
} from './routes/workspaceSearchParams'
1212

1313
const TWO_SECONDS_MS = 2 * 1000

node/services/product.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { fetchAppSettings } from './settings'
21
import type { SegmentData } from '../typings/Search'
2+
import { fetchAppSettings } from './settings'
33

44
export type ProductIdentifier = {
55
field: 'id' | 'slug' | 'ean' | 'reference' | 'sku'
@@ -144,6 +144,7 @@ export async function fetchProduct(
144144

145145
// Check if current account should skip comparison and use intsch directly
146146
if (shouldUseNewPDPEndpoint) {
147+
ctx.translated = true
147148
return fetchProductFromIntsch(ctx, args)
148149
}
149150

node/utils/i18n.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2+
createMessagesLoader,
23
formatTranslatableStringV2,
34
parseTranslatableStringV2,
4-
createMessagesLoader,
55
} from '@vtex/api'
66
import { logDegradedSearchError } from '../resolvers/search/utils'
77

@@ -28,13 +28,15 @@ export interface Message extends BaseMessage {
2828
}
2929

3030
export const addContextToTranslatableString = (message: Message, ctx: Context) => {
31-
const { vtex: { tenant } } = ctx
31+
const { vtex: { tenant }, translated } = ctx
3232
const { locale } = tenant!
3333

3434
if (!message.content) {
3535
return message.content
3636
}
3737

38+
const state = translated ? 'translated' : 'original'
39+
3840

3941
try {
4042
const {
@@ -45,7 +47,7 @@ export const addContextToTranslatableString = (message: Message, ctx: Context) =
4547

4648
const context = (originalContext || message.context)?.toString()
4749
const from = originalFrom || message.from || locale
48-
return formatTranslatableStringV2({ content, context, from })
50+
return formatTranslatableStringV2({ content, context, from, state })
4951
} catch (e) {
5052
logDegradedSearchError(ctx.vtex.logger, {
5153
service: 'node-vtex-api translation',

0 commit comments

Comments
 (0)