Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,49 @@ let defaultConfig = {
type recoilConfig = {
config: configClass,
themeObj: themeClass,
localeString: LocaleStringTypes.localeStrings,
constantString: LocaleStringTypes.constantStrings,
localeString: LocaleDataType.localeStrings,
constantString: LocaleDataType.constantStrings,
showLoader: bool,
}

let getLocaleFileName = locale => {
switch locale->LocaleDataType.localeStringToType {
| Some(En) => "en"
| Some(He) => "he"
| Some(Fr) => "fr"
| Some(En_GB) => "en-GB"
| Some(Ar) => "ar"
| Some(Ja) => "ja"
| Some(De) => "de"
| Some(Fr_BE) => "fr-BE"
| Some(Es) => "es"
| Some(Ca) => "ca"
// | Some(Zh) => "zh" // Pending support
| Some(Pt) => "pt"
| Some(It) => "it"
| Some(Pl) => "pl"
| Some(Nl) => "nl"
| Some(NI_BE) => "nl-BE" // to check
| Some(Sv) => "sv"
| Some(Ru) => "ru"
// | Some(Zh_HANT) => "zh-Hant" // Pending support
| Some(Lt) => "lt"
Comment on lines +87 to +97
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

zh and zh-Hant is used my merchants on prod

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes will add this in a stacked PR, working on that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

| Some(Cs) => "cs"
| Some(Sk) => "sk"
| Some(Ls) => "is" // to check
| Some(Cy) => "cy"
| Some(El) => "el"
| Some(Et) => "et"
| Some(Fi) => "fi"
| Some(Nb) => "no" // to check
| Some(Bs) => "bs"
| Some(Da) => "da"
| Some(Ms) => "ms"
| Some(Tr_CY) => "tr-CY"
| None => "en"
}
}

let getLocaleObject = async string => {
try {
let locale = if string == "auto" {
Expand All @@ -81,48 +119,27 @@ let getLocaleObject = async string => {
string
}

let promiseLocale = switch locale->LocaleStringHelper.mapLocalStringToTypeLocale {
| EN => Js.import(EnglishLocale.localeStrings)
| HE => Js.import(HebrewLocale.localeStrings)
| FR => Js.import(FrenchLocale.localeStrings)
| EN_GB => Js.import(EnglishGBLocale.localeStrings)
| AR => Js.import(ArabicLocale.localeStrings)
| JA => Js.import(JapaneseLocale.localeStrings)
| DE => Js.import(DeutschLocale.localeStrings)
| FR_BE => Js.import(FrenchBelgiumLocale.localeStrings)
| ES => Js.import(SpanishLocale.localeStrings)
| CA => Js.import(CatalanLocale.localeStrings)
| ZH => Js.import(ChineseLocale.localeStrings)
| PT => Js.import(PortugueseLocale.localeStrings)
| IT => Js.import(ItalianLocale.localeStrings)
| PL => Js.import(PolishLocale.localeStrings)
| NL => Js.import(DutchLocale.localeStrings)
| SV => Js.import(SwedishLocale.localeStrings)
| RU => Js.import(RussianLocale.localeStrings)
| ZH_HANT => Js.import(TraditionalChineseLocale.localeStrings)
}

let awaitedLocaleValue = await promiseLocale
awaitedLocaleValue
let localeFileName = getLocaleFileName(locale)
await S3Utils.getLocaleFromS3(localeFileName)
} catch {
| _ => EnglishLocale.localeStrings
| _ => LocaleDataType.defaultLocale
}
}

let getConstantStringsObject = async () => {
try {
let promiseConstantStrings = Js.import(ConstantStrings.constantStrings)
let promiseConstantStrings = Js.import(LocaleDataType.defaultConstantStrings)
await promiseConstantStrings
} catch {
| _ => ConstantStrings.constantStrings
| _ => LocaleDataType.defaultConstantStrings
}
}

let defaultRecoilConfig: recoilConfig = {
config: defaultConfig,
themeObj: defaultConfig.appearance.variables,
localeString: EnglishLocale.localeStrings,
constantString: ConstantStrings.constantStrings,
localeString: LocaleDataType.defaultLocale,
constantString: LocaleDataType.defaultConstantStrings,
showLoader: false,
}

Expand Down
4 changes: 2 additions & 2 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,10 @@ let getCardBrandFromStates = (cardBrand, cardScheme, showPaymentMethodsScreen) =
!showPaymentMethodsScreen ? cardScheme : cardBrand
}

let getCardBrandInvalidError = (~cardBrand, ~localeString: LocaleStringTypes.localeStrings) => {
let getCardBrandInvalidError = (~cardBrand, ~localeString: LocaleDataType.localeStrings) => {
switch cardBrand {
| "" => localeString.enterValidCardNumberErrorText
| cardBrandValue => localeString.cardBrandConfiguredErrorText(cardBrandValue)
| cardBrandValue => `${cardBrandValue}${localeString.cardBrandConfiguredErrorText}`
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/BillingNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ let make = (~customFieldName=None, ~requiredFields as optionalRequiredFields=?)
if billingName.value == "" {
setBillingName(prev => {
...prev,
errorString: fieldName->localeString.nameEmptyText,
errorString: `${localeString.nameEmptyText}${fieldName}`,
})
} else {
switch optionalRequiredFields {
| Some(requiredFields) =>
if !DynamicFieldsUtils.checkIfNameIsValid(requiredFields, BillingName, billingName) {
setBillingName(prev => {
...prev,
errorString: fieldName->localeString.completeNameEmptyText,
errorString: `${localeString.completeNameEmptyText}${fieldName}`,
})
}
| None => ()
Expand Down
4 changes: 2 additions & 2 deletions src/Components/FullNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let make = (~customFieldName=None, ~optionalRequiredFields=None) => {
if fullName.value == "" {
setFullName(prev => {
...prev,
errorString: fieldName->localeString.nameEmptyText,
errorString: `${localeString.nameEmptyText}${fieldName}`,
})
} else if !(fullName.isValid->Option.getOr(false)) {
setFullName(prev => {
Expand All @@ -50,7 +50,7 @@ let make = (~customFieldName=None, ~optionalRequiredFields=None) => {
if !DynamicFieldsUtils.checkIfNameIsValid(requiredFields, FullName, fullName) {
setFullName(prev => {
...prev,
errorString: fieldName->localeString.completeNameEmptyText,
errorString: `${localeString.completeNameEmptyText}${fieldName}`,
})
}
| None => ()
Expand Down
5 changes: 1 addition & 4 deletions src/Components/GiftCards.res
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ let make = (~giftCardOptions) => {
let giftCardPaymentInfoMessage =
remainingAmount === 0.0
? ` ${localeString.giftCardPaymentCompleteMessage}`
: ` ${localeString.giftCardPaymentRemainingMessage(
remainingCurrency,
remainingAmount->Float.toString,
)}`
: ` ${localeString.giftCardPaymentRemainingMessagePart1}${remainingCurrency} ${remainingAmount->Float.toString}${localeString.giftCardPaymentRemainingMessagePart2}`

let getPrimaryGiftCardData = (~appliedGiftCards: array<GiftCardTypes.appliedGiftCard>) =>
appliedGiftCards->Array.get(0)->Option.getOr(GiftCardTypes.defaultAppliedGiftCard)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SaveDetailsCheckbox.res
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let make = (~isChecked, ~setIsChecked) => {
} else if customMessageForCardTerms->String.length > 0 {
customMessageForCardTerms
} else {
localeString.cardTerms(business.name)
localeString.cardTermsPart1 ++ business.name ++ localeString.cardTermsPart2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please write it using string templates

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We tried implementing it using string templates but some string interpolations like surchargeMsgAmount require rendering parts of the text in bold, which involves platform-specific React logic. Since the locale utils are shared between the web and mobile SDKs, adding such rendering logic there isn't feasible.

Because of outliers like this, abstracting string interpolation into shared util functions would be inconsistent — we'd have utils for some cases but not others.

Also, locale strings were split into parts so that consumers can freely decide how to join and display them. Adding a shared util that does the joining for them would defeat that purpose.

}

<div
Expand Down
21 changes: 17 additions & 4 deletions src/Components/SurchargeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type oneClickWallets = {
paymentMethodType: string,
displayName: string,
}
let oneClickWallets = (~localeString: LocaleStringTypes.localeStrings) => [
let oneClickWallets = (~localeString: LocaleDataType.localeStrings) => [
{
paymentMethodType: "apple_pay",
displayName: localeString.payment_methods_apple_pay,
Expand Down Expand Up @@ -80,12 +80,25 @@ let useMessageGetter = () => {
let surchargeValue = surchargeDetails.displayTotalSurchargeAmount->Float.toString

if showShortSurchargeMessage {
Some(localeString.shortSurchargeMessage(currency, surchargeValue))
Some(<>
{React.string(`${localeString.shortSurchargeMessagePart1}${Utils.nbsp}`)}
<strong>
{React.string(`${currency} ${surchargeValue}${localeString.shortSurchargeMessagePart2}`)}
</strong>
</>)
} else {
let message = if paymentMethod === "card" {
localeString.surchargeMsgAmountForCard(currency, surchargeValue)
<>
{React.string(`${localeString.surchargeMsgAmountForCardPart1}${Utils.nbsp}`)}
<strong> {React.string(`${currency} ${surchargeValue}`)} </strong>
{React.string(`${Utils.nbsp}${localeString.surchargeMsgAmountForCardPart2}`)}
</>
} else {
localeString.surchargeMsgAmount(currency, surchargeValue)
<>
{React.string(`${localeString.surchargeMsgAmountPart1}${Utils.nbsp}`)}
<strong> {React.string(`${currency} ${surchargeValue}`)} </strong>
{React.string(`${Utils.nbsp}${localeString.surchargeMsgAmountPart2}`)}
</>
}

Some(message)
Expand Down
12 changes: 9 additions & 3 deletions src/Components/Terms.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ let make = (~styles: JsxDOMStyle.t={}, ~paymentMethod, ~paymentMethodType) => {
let cardTermsValue =
customMessageForCardTerms != ""
? customMessageForCardTerms
: localeString.cardTerms(business.name)
: `${localeString.cardTermsPart1}${business.name}${localeString.cardTermsPart2}`

let paymentMethodTermsDefaults = switch paymentMethod {
| "bank_debit" =>
switch paymentMethodType {
| "sepa" => (localeString.sepaDebitTerms(business.name), terms.sepaDebit)
| "sepa" => (
`${localeString.sepaDebitTermsPart1}${business.name}${localeString.sepaDebitTermsPart2}${business.name}${localeString.sepaDebitTermsPart3}`,
terms.sepaDebit,
)
| "becs" => (localeString.becsDebitTerms, terms.auBecsDebit)
| "ach" => (localeString.achBankDebitTerms(business.name), terms.usBankAccount)
| "ach" => (
`${localeString.achBankDebitTermsPart1}${business.name}${localeString.achBankDebitTermsPart2}`,
terms.usBankAccount,
)
| _ => ("", Never)
}
| "card" =>
Expand Down
16 changes: 7 additions & 9 deletions src/FormViewJourney.res
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ let make = (
| Card => localeString.formHeaderEnterCardText
| BankRedirect
| BankTransfer =>
key->localeString.formHeaderBankText
| Wallet => key->localeString.formHeaderWalletText
`${localeString.formHeaderBankTextPart1}${key}${localeString.formHeaderBankTextPart2}`
| Wallet =>
`${localeString.formHeaderWalletTextPart1}${key}${localeString.formHeaderWalletTextPart2}`
},
true,
)}
Expand All @@ -343,9 +344,7 @@ let make = (
<img src={"merchantLogo"} alt="" className="h-6 w-auto" />
<div className="ml-1.5">
{React.string(
pmt
->getPaymentMethodTypeLabel
->localeString.formHeaderReviewTabLayoutText,
`${localeString.formHeaderReviewTabLayoutTextPart1}${pmt->getPaymentMethodTypeLabel}${localeString.formHeaderReviewTabLayoutTextPart2}`,
)}
</div>
</div>
Expand Down Expand Up @@ -394,10 +393,9 @@ let make = (
className="flex flex-row items-center min-w-full my-5 px-2.5 py-1.5 text-xs border border-solid border-blue-200 rounded bg-blue-50">
<img src={"merchantLogo"} alt="" className="h-3 w-auto mr-1.5" />
{React.string(
pm
->getPaymentMethodLabel
->String.toLowerCase
->localeString.formFundsCreditInfoText,
`${localeString.formFundsCreditInfoTextPart1}${pm
->getPaymentMethodLabel
->String.toLowerCase}${localeString.formFundsCreditInfoTextPart2}`,
)}
</div>
<div className="flex my-5 text-lg font-semibold w-full">
Expand Down
16 changes: 7 additions & 9 deletions src/FormViewTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ let make = (
| Card(_) => localeString.formHeaderEnterCardText
| BankRedirect(_)
| BankTransfer(_) =>
key->localeString.formHeaderBankText
| Wallet(_) => key->localeString.formHeaderWalletText
`${localeString.formHeaderBankTextPart1}${key}${localeString.formHeaderBankTextPart2}`
| Wallet(_) =>
`${localeString.formHeaderWalletTextPart1}${key}${localeString.formHeaderWalletTextPart2}`
}->React.string}
</div>
{payoutDynamicFields.payoutMethodData->renderPayoutMethodForm->React.array}
Expand Down Expand Up @@ -277,9 +278,7 @@ let make = (
<img src={"merchantLogo"} alt="" className="h-6 w-auto" />
<div className="ml-1.5">
{React.string(
pmt
->getPaymentMethodTypeLabel
->localeString.formHeaderReviewTabLayoutText,
`${localeString.formHeaderReviewTabLayoutTextPart1}${pmt->getPaymentMethodTypeLabel}${localeString.formHeaderReviewTabLayoutTextPart2}`,
)}
</div>
</div>
Expand Down Expand Up @@ -328,10 +327,9 @@ let make = (
className="flex flex-row items-center min-w-full my-5 px-2.5 py-1.5 text-xs border border-solid border-blue-200 rounded bg-blue-50">
<img src={"merchantLogo"} alt="" className="h-3 w-auto mr-1.5" />
{React.string(
pm
->getPaymentMethodLabel
->String.toLowerCase
->localeString.formFundsCreditInfoText,
`${localeString.formFundsCreditInfoTextPart1}${pm
->getPaymentMethodLabel
->String.toLowerCase}${localeString.formFundsCreditInfoTextPart2}`,
)}
</div>
<div className="flex my-5 text-lg font-semibold w-full">
Expand Down
Loading
Loading