Browse Source

购物车翻译

main
Mac 2 weeks ago
parent
commit
af1d75b79a
  1. 325
      app/screens/CartScreen.tsx
  2. 26
      app/utils/languageUtils.ts

325
app/screens/CartScreen.tsx

@ -33,6 +33,7 @@ import useUserStore from "../store/user";
import { t } from "../i18n";
import { payApi } from "../services/api/payApi";
import IconComponent from "../components/IconComponent";
import {getSubjectTransLanguage,getAttributeTransLanguage} from "../utils/languageUtils";
export const CartScreen = () => {
const [cartList, setCartList] = useState<GetCartList[]>([]);
@ -705,8 +706,12 @@ export const CartScreen = () => {
style={styles.imageThumbnail}
/>
<View style={styles.productInfoContainer2}>
<Text style={styles.casualTextSnippet}>
{item.subject}
<Text
style={styles.casualTextSnippet}
numberOfLines={2}
ellipsizeMode="tail"
>
{getSubjectTransLanguage(item)}
</Text>
<Text style={styles.productDetailsTextStyle1}>
{t("cart.min_order")}: {item.min_order_quantity}
@ -714,199 +719,189 @@ export const CartScreen = () => {
</Text>
</View>
</View>
{item.skus.map((sku, index) => (
<Swipeable
key={sku.cart_item_id}
enabled={!!user_id}
renderRightActions={() => (
<TouchableOpacity
style={{
backgroundColor: "#ff5217",
justifyContent: "center",
alignItems: "center",
width: 80,
}}
onPress={() =>
handleDeleteSku(
{item.skus.map((sku, index) => {
return (
<Swipeable
key={sku.cart_item_id}
enabled={!!user_id}
renderRightActions={() => (
<TouchableOpacity
style={{
backgroundColor: "#ff5217",
justifyContent: "center",
alignItems: "center",
width: 80,
}}
onPress={() => handleDeleteSku(
item.cart_id,
sku.cart_item_id,
item.cart_id
)
}
disabled={!user_id}
>
<Text
style={{ color: "white", fontWeight: "bold" }}
)}
disabled={!user_id}
>
{t("cart.delete")}
</Text>
</TouchableOpacity>
)}
>
<TouchableOpacity
onPress={() => {
if (user_id) {
navigation.navigate("ProductDetail", {
offer_id: item.offer_id,
searchKeyword: item.subject,
price: sku.price,
});
}
}}
style={[
styles.productCardContainer5,
styles.productCardContainer4,
]}
<Text
style={{ color: "white", fontWeight: "bold" }}
>
{t("cart.delete")}
</Text>
</TouchableOpacity>
)}
>
<View style={styles.svgContainer1}>
<TouchableOpacity
onPress={() =>
user_id && toggleSelection(
<TouchableOpacity
onPress={() => {
if (user_id) {
navigation.navigate("ProductDetail", {
offer_id: item.offer_id,
searchKeyword: item.subject,
price: sku.price,
});
}
} }
style={[
styles.productCardContainer5,
styles.productCardContainer4,
]}
>
<View style={styles.svgContainer1}>
<TouchableOpacity
onPress={() => user_id && toggleSelection(
String(sku.cart_item_id),
index1,
index
)
}
disabled={!user_id}
>
<View style={[styles.iconContainer]}>
{sku.selected === 1 ? (
<OrangeCircleIcon size={fontSize(24)} />
) : (
<CircleOutlineIcon size={fontSize(24)} />
)}
{/* <CircleOutlineIcon size={fontSize(24)} strokeColor={sku.selected === 1 ? "#FF5100" : "#C6C6C6"}/> */}
</View>
</TouchableOpacity>
</View>
<Image
source={{
uri: sku.attributes[0]?.sku_image_url
? sku.attributes[0]?.sku_image_url
: item.product_image,
}}
style={styles.productImageDisplayStyle}
/>
<View style={styles.productCardWidget1}>
{/* 1. SKU attributes at the top */}
{sku.attributes[0]?.value && (
<View style={styles.longLifeRougeStyle}>
<Text
style={styles.longLifeTextSnippet}
numberOfLines={2}
ellipsizeMode="tail"
>
{sku.attributes[0]?.value}{" "}
{sku.attributes[1] ? "/" : ""}{" "}
{sku.attributes[1]?.value}
</Text>
</View>
)}
{/* 2. Price section - discount and actual price close together */}
<View style={styles.priceSection}>
<View style={styles.priceColumnContainer}>
{/* Discount price */}
<View style={styles.productInfoContainer1}>
<View style={styles.priceInfoContainer1}>
<Text style={styles.discountPriceLabel}>
{sku.original_price} {sku.currency}
</Text>
</View>
<View style={styles.vipContainer}>
<Image
source={require("../../assets/img/折扣VIP1 (1).png")}
style={styles.VipImg}
/>
<Text style={styles.discountPercentageTextStyle}>
-{((1 - vip_discount) * 100).toFixed(0)}%
</Text>
</View>
disabled={!user_id}
>
<View style={[styles.iconContainer]}>
{sku.selected === 1 ? (
<OrangeCircleIcon size={fontSize(24)} />
) : (
<CircleOutlineIcon size={fontSize(24)} />
)}
{/* <CircleOutlineIcon size={fontSize(24)} strokeColor={sku.selected === 1 ? "#FF5100" : "#C6C6C6"}/> */}
</View>
</TouchableOpacity>
</View>
<Image
source={{
uri: sku.attributes[0]?.sku_image_url
? sku.attributes[0]?.sku_image_url
: item.product_image,
}}
style={styles.productImageDisplayStyle} />
<View style={styles.productCardWidget1}>
{/* 1. SKU attributes at the top */}
{sku.attributes[0]?.value && (
<View style={styles.longLifeRougeStyle}>
<Text
style={styles.longLifeTextSnippet}
numberOfLines={2}
ellipsizeMode="tail"
>
{getAttributeTransLanguage(sku.attributes[0])}{" "}
{sku.attributes[1] ? "/" : ""}{" "}
{sku.attributes[1] ? getAttributeTransLanguage(sku.attributes[1]) : ""}
</Text>
</View>
)}
{/* Actual price - right below discount price */}
<View style={styles.productInfoContainer4}>
<Text style={styles.productCodeLabel}>
{sku.price}
{/* 2. Price section - discount and actual price close together */}
<View style={styles.priceSection}>
<View style={styles.priceColumnContainer}>
{/* Discount price */}
<View style={styles.productInfoContainer1}>
<View style={styles.priceInfoContainer1}>
<Text style={styles.discountPriceLabel}>
{sku.original_price} {sku.currency}
</Text>
<Text style={styles.productDetailsTextStyle}>
{sku.currency}
</View>
<View style={styles.vipContainer}>
<Image
source={require("../../assets/img/折扣VIP1 (1).png")}
style={styles.VipImg} />
<Text style={styles.discountPercentageTextStyle}>
-{((1 - vip_discount) * 100).toFixed(0)}%
</Text>
</View>
</View>
{/* 3. Quantity controls on the right */}
<View style={styles.orderQuantityContainer}>
<TouchableOpacity
style={[
styles.svgContainer4,
{ borderRightWidth: 0 },
]}
onPress={() =>
user_id && handleDecreaseQuantity(
{/* Actual price - right below discount price */}
<View style={styles.productInfoContainer4}>
<Text style={styles.productCodeLabel}>
{sku.price}
</Text>
<Text style={styles.productDetailsTextStyle}>
{sku.currency}
</Text>
</View>
</View>
{/* 3. Quantity controls on the right */}
<View style={styles.orderQuantityContainer}>
<TouchableOpacity
style={[
styles.svgContainer4,
{ borderRightWidth: 0 },
]}
onPress={() => user_id && handleDecreaseQuantity(
item.cart_id,
sku.cart_item_id,
sku.quantity,
item.min_order_quantity
)
}
disabled={!user_id}
>
<Text
style={{
fontSize: fontSize(18),
color: "#333",
fontWeight: "500",
}}
)}
disabled={!user_id}
>
-
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.quantityLabelContainer}
onPress={() =>
user_id && handleQuantityPress(
<Text
style={{
fontSize: fontSize(18),
color: "#333",
fontWeight: "500",
}}
>
-
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.quantityLabelContainer}
onPress={() => user_id && handleQuantityPress(
item.cart_id,
sku.cart_item_id,
sku.quantity
)
}
disabled={!user_id}
>
<Text style={styles.quantityText}>
{sku.quantity}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[
styles.svgContainer4,
{ borderLeftWidth: 0, marginLeft: 0 },
]}
onPress={() =>
user_id && handleIncreaseQuantity(
)}
disabled={!user_id}
>
<Text style={styles.quantityText}>
{sku.quantity}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[
styles.svgContainer4,
{ borderLeftWidth: 0, marginLeft: 0 },
]}
onPress={() => user_id && handleIncreaseQuantity(
item.cart_id,
sku.cart_item_id,
sku.quantity
)
}
disabled={!user_id}
>
<Text
style={{
fontSize: fontSize(18),
color: "#333",
fontWeight: "500",
}}
)}
disabled={!user_id}
>
+
</Text>
</TouchableOpacity>
<Text
style={{
fontSize: fontSize(18),
color: "#333",
fontWeight: "500",
}}
>
+
</Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</TouchableOpacity>
</Swipeable>
))}
</TouchableOpacity>
</Swipeable>
);
})}
</View>
))}

26
app/utils/languageUtils.ts

@ -30,6 +30,32 @@ export const getSubjectTransLanguage = <T extends Record<string, any>>(data: T):
export const getAttributeTransLanguage = <T extends Record<string, any>>(data: T): string => {
// 获取当前i18n语言
const currentLang = getCurrentLanguage();
// 特殊处理中文
if (currentLang === 'zh' && 'value' in data) {
return data.value as string;
}
// 获取所有value_trans开头的字段
const translationFields = Object.keys(data).filter(key =>
key.startsWith('value_trans')
);
// 查找匹配的字段
const matchedField = translationFields.find(field => {
// 从字段名中提取语言代码
const langCode = field.replace('value_trans_', '');
// 如果没有后缀,则为法语
return langCode === '' ? currentLang === 'fr' : langCode === currentLang;
});
// 返回匹配的翻译值,如果没有匹配则返回法语
return (data[matchedField || 'value_trans'] as string) || '';
};
export const getSkuTransLanguage = <T extends Record<string, any>>(data: T): string => {
// 获取当前i18n语言
const currentLang = getCurrentLanguage();

Loading…
Cancel
Save