-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from vtex-apps/fix/source-language-from-tenant
Fix source language from tenant
- Loading branch information
Showing
5 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,35 @@ | ||
import { | ||
formatTranslatableStringV2, | ||
parseTranslatableStringV2, | ||
} from '@vtex/api' | ||
|
||
export const formatTranslatableProp = <R, P extends keyof R, I extends keyof R>(prop: P, idProp: I) => | ||
(root: R, _: unknown, ctx: Context) => addContextToTranslatableString( | ||
{ | ||
content: root[prop] as unknown as string, | ||
context: root[idProp] as unknown as string | ||
}, | ||
ctx | ||
) | ||
|
||
interface Message { | ||
content: string, | ||
context: string, | ||
from?: string | ||
} | ||
|
||
export const addContextToTranslatableString = (message: Message, ctx: Context) => { | ||
const { vtex: { tenant } } = ctx | ||
const { locale } = tenant! | ||
|
||
const { | ||
content, | ||
context: originalContext, | ||
from: originalFrom | ||
} = parseTranslatableStringV2(message.content) | ||
|
||
const context = originalContext || message.context | ||
const from = originalFrom || message.from || locale | ||
|
||
return formatTranslatableStringV2({content, context, from}) | ||
} |
This file contains 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