Skip to content
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

fix bug with same key in one context #273

Merged
merged 1 commit into from
Dec 22, 2023
Merged

Conversation

stoyanovk
Copy link
Contributor

fix bug that was in issue #209

@stoyanovk stoyanovk requested a review from AlexMost December 12, 2023 14:16
src/utils.ts Outdated
@@ -175,6 +175,11 @@ export function transformCompactObj(compactObj: TTagCompactTranslations) {
const msgid = msgids[j];
const translations = compactObj.contexts[ctx][msgid];
const [newMsgid, newTranslations] = transformCompactTranslate(msgid, translations);
if (process.env.NODE_ENV !== 'production' && newContext[newMsgid]) {
throw new Error(
`Wrong data! Context "${ctx}" already have key "${newMsgid}", You should change key "${msgid}" or use different context`,
Copy link
Member

@AlexMost AlexMost Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can improve the error message, lets rephrase that to something like:

const [newMsgid, newTranslations] = transformCompactTranslate(msgid, translations);
const existingMsgid = newContext[newMsgid];
...
throw new Error(`Duplicate msgid (${msgid} and ${existingMsgid} will be interpreted as the same key)  this potentially can lead to translation loss. Consider using context for one of those msgid`s. See the context doc here - https://ttag.js.org/docs/context.html`)

@stoyanovk stoyanovk force-pushed the fix_for_bug_with_same_key branch 2 times, most recently from e810cc4 to cf34732 Compare December 20, 2023 08:34
@stoyanovk stoyanovk force-pushed the fix_for_bug_with_same_key branch from cf34732 to c2c8eff Compare December 22, 2023 10:29
@AlexMost AlexMost merged commit 212bf9d into master Dec 22, 2023
1 check passed
@AlexMost AlexMost deleted the fix_for_bug_with_same_key branch December 22, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants