forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace localize import with new library (deriv-com#16140)
* chore: replace localize import with new library * chore: removed unused component
- Loading branch information
1 parent
bd32ef2
commit 1486143
Showing
11 changed files
with
95 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
const Localize = ({ i18n_default_text, values }) => { | ||
// Replace placeholders in the default text with actual values | ||
const localizedText = i18n_default_text.replace(/\{\{(\w+)\}\}/g, (match, key) => values[key] || match); | ||
import React from 'react'; | ||
|
||
return localizedText || null; | ||
const replaceValue = (text, values) => { | ||
const valueMatch = text.match(/{{(\w+)}}/); | ||
if (valueMatch) { | ||
const valueKey = valueMatch[1]; | ||
return values[valueKey] || text; | ||
} | ||
return text; | ||
}; | ||
|
||
const Localize = ({ i18n_default_text, components = [], values = {} }) => { | ||
// Split text into parts, extracting placeholders for components | ||
const parts = i18n_default_text.split(/(<\d+>.*?<\/\d+>|{{\w+}})/g); | ||
|
||
return ( | ||
<> | ||
{parts.map((part, index) => { | ||
// Handle component placeholders | ||
const componentMatch = part.match(/<(\d+)>(.*?)<\/\1>/); | ||
if (componentMatch) { | ||
const componentIndex = parseInt(componentMatch[1]); | ||
const content = replaceValue(componentMatch[2], values); | ||
const Component = components[componentIndex]; | ||
return Component ? React.cloneElement(Component, { key: index, children: content }) : content; | ||
} | ||
// Replace placeholders with actual values | ||
return replaceValue(part, values); | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
const mockFn = jest.fn((text, args) => { | ||
return text.replace(/{{(.*?)}}/g, (_, match) => args[match.trim()]); | ||
}); | ||
|
||
// Mock for useTranslations hook | ||
const useTranslations = () => ({ | ||
localize: jest.fn((text, args) => { | ||
return text.replace(/{{(.*?)}}/g, (_, match) => args[match.trim()]); | ||
}), | ||
localize: mockFn, | ||
currentLang: 'EN', | ||
}); | ||
|
||
const localize = jest.fn(text => text); | ||
const localize = mockFn; | ||
|
||
const getAllowedLanguages = jest.fn(() => ({ EN: 'English', VI: 'Tiếng Việt' })); | ||
|
||
export { Localize, localize, useTranslations, getAllowedLanguages }; | ||
export { Localize, localize, useTranslations, getAllowedLanguages }; |
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
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
2 changes: 1 addition & 1 deletion
2
packages/account/src/Sections/Assessment/FinancialAssessment/financial-information-list.ts
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