Browse Source

购物车翻译

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

55
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,7 +719,8 @@ export const CartScreen = () => {
</Text>
</View>
</View>
{item.skus.map((sku, index) => (
{item.skus.map((sku, index) => {
return (
<Swipeable
key={sku.cart_item_id}
enabled={!!user_id}
@ -726,13 +732,11 @@ export const CartScreen = () => {
alignItems: "center",
width: 80,
}}
onPress={() =>
handleDeleteSku(
onPress={() => handleDeleteSku(
item.cart_id,
sku.cart_item_id,
item.cart_id
)
}
)}
disabled={!user_id}
>
<Text
@ -760,13 +764,11 @@ export const CartScreen = () => {
>
<View style={styles.svgContainer1}>
<TouchableOpacity
onPress={() =>
user_id && toggleSelection(
onPress={() => user_id && toggleSelection(
String(sku.cart_item_id),
index1,
index
)
}
)}
disabled={!user_id}
>
<View style={[styles.iconContainer]}>
@ -785,8 +787,7 @@ export const CartScreen = () => {
? sku.attributes[0]?.sku_image_url
: item.product_image,
}}
style={styles.productImageDisplayStyle}
/>
style={styles.productImageDisplayStyle} />
<View style={styles.productCardWidget1}>
{/* 1. SKU attributes at the top */}
{sku.attributes[0]?.value && (
@ -796,9 +797,9 @@ export const CartScreen = () => {
numberOfLines={2}
ellipsizeMode="tail"
>
{sku.attributes[0]?.value}{" "}
{getAttributeTransLanguage(sku.attributes[0])}{" "}
{sku.attributes[1] ? "/" : ""}{" "}
{sku.attributes[1]?.value}
{sku.attributes[1] ? getAttributeTransLanguage(sku.attributes[1]) : ""}
</Text>
</View>
)}
@ -816,8 +817,7 @@ export const CartScreen = () => {
<View style={styles.vipContainer}>
<Image
source={require("../../assets/img/折扣VIP1 (1).png")}
style={styles.VipImg}
/>
style={styles.VipImg} />
<Text style={styles.discountPercentageTextStyle}>
-{((1 - vip_discount) * 100).toFixed(0)}%
</Text>
@ -842,14 +842,12 @@ export const CartScreen = () => {
styles.svgContainer4,
{ borderRightWidth: 0 },
]}
onPress={() =>
user_id && handleDecreaseQuantity(
onPress={() => user_id && handleDecreaseQuantity(
item.cart_id,
sku.cart_item_id,
sku.quantity,
item.min_order_quantity
)
}
)}
disabled={!user_id}
>
<Text
@ -864,13 +862,11 @@ export const CartScreen = () => {
</TouchableOpacity>
<TouchableOpacity
style={styles.quantityLabelContainer}
onPress={() =>
user_id && handleQuantityPress(
onPress={() => user_id && handleQuantityPress(
item.cart_id,
sku.cart_item_id,
sku.quantity
)
}
)}
disabled={!user_id}
>
<Text style={styles.quantityText}>
@ -882,13 +878,11 @@ export const CartScreen = () => {
styles.svgContainer4,
{ borderLeftWidth: 0, marginLeft: 0 },
]}
onPress={() =>
user_id && handleIncreaseQuantity(
onPress={() => user_id && handleIncreaseQuantity(
item.cart_id,
sku.cart_item_id,
sku.quantity
)
}
)}
disabled={!user_id}
>
<Text
@ -906,7 +900,8 @@ export const CartScreen = () => {
</View>
</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