Add English Translations to CN-prefixed Elements in an Array
This tutorial demonstrates how to add English translations to elements prefixed with 'cn_' in an array. The primary focus is on the 'profit_list' section of the array.
Original Data:
8 => [
'svip_level' => 1,
'amount' => 1500000000,
//'total_amount' => 1000000,
'keep_amount' => 1500000000,
'reward_amount' => 300000,
'profit_list' => [
'month_gold' => ['name' => 'month_gold', 'image_url' => '', 'amount' => 300000, 'cn_title' => '月P豆奖励', 'cn_sub_title' => '奖励300,000P豆', 'cn_alter' => '当月最多领取一次,不累积', 'reward_type' => 'month', 'is_new' => 1],
'week_gold' => ['name' => 'week_gold', 'image_url' => '', 'amount' => 50000, 'cn_title' => '周P豆奖励', 'cn_sub_title' => '奖励50,000P豆', 'cn_alter' => '每周一刷新,不累积', 'reward_type' => 'week', 'is_new' => 1],
'prop_restore' => ['name' => 'prop_high_restore', 'image_url' => '', 'amount' => 2, 'cn_title' => '月道具奖励', 'cn_sub_title' => '奖励道具高级回血卡*2', 'reward_type' => 'month', 'cn_alter' => '当月最多领取一次,不累积', 'is_new' => 1],
'week_gold_rebate' => ['name' => 'gold_rebate', 'image_url' => '', 'amount' => 0.007, 'max_amount' => 150000, 'cn_title' => '每周消耗返利', 'cn_sub_title' => '奖励%sP豆', 'cn_alter' => '每周可领取上周返利,最多150,000P豆,不累积', 'reward_type' => 'week', 'is_new' => 1],
'free_box'=> ['name' => 'free_box', 'image_url' => '', 'amount' => 4, 'cn_title' => 'SVIP专属盲盒', 'cn_sub_title' => '每月免费4次', 'cn_alter' => '每月1日刷新,次数不累积', 'is_new' => 1],
'free_roll'=> ['name' => 'free_box', 'image_url' => '', 'amount' => 1, 'cn_title' => 'SVIP ROLL房', 'cn_sub_title' => '每周免费参与', 'cn_alter' => '', 'is_new' => 1],
'svip_mall_discount' => ['name' => 'svip_mall_discount', 'image_url' => '', 'amount' => 0.06, 'cn_title' => 'SVIP商城优惠', 'cn_sub_title' => '商品享受6%减免', 'cn_alter' => '', 'is_new' => 1],
'recharge_bonus' =>['name' => 'recharge_bonus', 'image_url' => '', 'amount' => 0.02, 'cn_title' => '充值赠送P豆', 'cn_sub_title' => '转化比例2%', 'cn_alter' => '', 'is_new' => 1],
'gold_transform_diamond' => ['name' => 'gold_transform_diamond', 'cn_title' => '消耗解锁钻石', 'cn_sub_title' => '转化比例2%', 'cn_alter' => ''],
'recharge_transform_diamond' => ['name' => 'gold_transform_diamond', 'cn_title' => '充值解锁钻石', 'cn_sub_title' => '转化比例8%', 'cn_alter' => ''],
'svip_mall' => ['name' => 'svip_mall', 'cn_title' => '全新svip商城', 'cn_sub_title' => '热门饰品不断货', 'cn_alter' => ''],
'customer_service' => ['name' => 'customer_service', 'cn_title' => '专属客服接待', 'cn_sub_title' => '专人专线服务', 'cn_alter' => ''],
'item_withdraw' => ['name' => 'item_withdraw', 'amount' => 0,'cn_title' => '饰品快速取回', 'cn_sub_title' => '48h取回速率', 'cn_alter' => ''],
]
],
Modified Data:
8 => [
'svip_level' => 1,
'amount' => 1500000000,
//'total_amount' => 1000000,
'keep_amount' => 1500000000,
'reward_amount' => 300000,
'profit_list' => [
'month_gold' => ['name' => 'month_gold', 'image_url' => '', 'amount' => 300000, 'cn_title' => '月P豆奖励', 'cn_sub_title' => '奖励300,000P豆', 'cn_alter' => '当月最多领取一次,不累积', 'reward_type' => 'month', 'is_new' => 1, 'en_title' => 'Monthly P Bean Reward', 'en_sub_title' => 'Reward 300,000 P Beans', 'en_alter' => 'Can be claimed once per month, not cumulative'],
'week_gold' => ['name' => 'week_gold', 'image_url' => '', 'amount' => 50000, 'cn_title' => '周P豆奖励', 'cn_sub_title' => '奖励50,000P豆', 'cn_alter' => '每周一刷新,不累积', 'reward_type' => 'week', 'is_new' => 1, 'en_title' => 'Weekly P Bean Reward', 'en_sub_title' => 'Reward 50,000 P Beans', 'en_alter' => 'Refreshes every Monday, not cumulative'],
'prop_restore' => ['name' => 'prop_high_restore', 'image_url' => '', 'amount' => 2, 'cn_title' => '月道具奖励', 'cn_sub_title' => '奖励道具高级回血卡*2', 'reward_type' => 'month', 'cn_alter' => '当月最多领取一次,不累积', 'is_new' => 1, 'en_title' => 'Monthly Prop Reward', 'en_sub_title' => 'Reward 2 Advanced Health Recovery Cards', 'en_alter' => 'Can be claimed once per month, not cumulative'],
'week_gold_rebate' => ['name' => 'gold_rebate', 'image_url' => '', 'amount' => 0.007, 'max_amount' => 150000, 'cn_title' => '每周消耗返利', 'cn_sub_title' => '奖励%sP豆', 'cn_alter' => '每周可领取上周返利,最多150,000P豆,不累积', 'reward_type' => 'week', 'is_new' => 1, 'en_title' => 'Weekly Consumption Rebate', 'en_sub_title' => 'Reward %s P Beans', 'en_alter' => 'Can claim last week's rebate every week, up to 150,000 P Beans, not cumulative'],
'free_box'=> ['name' => 'free_box', 'image_url' => '', 'amount' => 4, 'cn_title' => 'SVIP专属盲盒', 'cn_sub_title' => '每月免费4次', 'cn_alter' => '每月1日刷新,次数不累积', 'is_new' => 1, 'en_title' => 'Exclusive SVIP Blind Box', 'en_sub_title' => 'Free 4 times per month', 'en_alter' => 'Refreshes on the 1st of every month, not cumulative'],
'free_roll'=> ['name' => 'free_box', 'image_url' => '', 'amount' => 1, 'cn_title' => 'SVIP ROLL房', 'cn_sub_title' => '每周免费参与', 'cn_alter' => '', 'is_new' => 1, 'en_title' => 'SVIP ROLL Room', 'en_sub_title' => 'Free participation every week', 'en_alter' => ''],
'svip_mall_discount' => ['name' => 'svip_mall_discount', 'image_url' => '', 'amount' => 0.06, 'cn_title' => 'SVIP商城优惠', 'cn_sub_title' => '商品享受6%减免', 'cn_alter' => '', 'is_new' => 1, 'en_title' => 'SVIP Mall Discount', 'en_sub_title' => 'Enjoy 6% off on products', 'en_alter' => ''],
'recharge_bonus' =>['name' => 'recharge_bonus', 'image_url' => '', 'amount' => 0.02, 'cn_title' => '充值赠送P豆', 'cn_sub_title' => '转化比例2%', 'cn_alter' => '', 'is_new' => 1, 'en_title' => 'Recharge Bonus P Beans', 'en_sub_title' => 'Conversion ratio 2%', 'en_alter' => ''],
'gold_transform_diamond' => ['name' => 'gold_transform_diamond', 'cn_title' => '消耗解锁钻石', 'cn_sub_title' => '转化比例2%', 'cn_alter' => '', 'en_title' => 'Unlock Diamonds by Consumption', 'en_sub_title' => 'Conversion ratio 2%', 'en_alter' => ''],
'recharge_transform_diamond' => ['name' => 'gold_transform_diamond', 'cn_title' => '充值解锁钻石', 'cn_sub_title' => '转化比例8%', 'cn_alter' => '', 'en_title' => 'Unlock Diamonds by Recharge', 'en_sub_title' => 'Conversion ratio 8%', 'en_alter' => ''],
'svip_mall' => ['name' => 'svip_mall', 'cn_title' => '全新svip商城', 'cn_sub_title' => '热门饰品不断货', 'cn_alter' => '', 'en_title' => 'Brand New SVIP Mall', 'en_sub_title' => 'Popular accessories constantly in stock', 'en_alter' => ''],
'customer_service' => ['name' => 'customer_service', 'cn_title' => '专属客服接待', 'cn_sub_title' => '专人专线服务', 'cn_alter' => '', 'en_title' => 'Exclusive Customer Service Reception', 'en_sub_title' => 'Dedicated one-on-one service', 'en_alter' => ''],
'item_withdraw' => ['name' => 'item_withdraw', 'amount' => 0,'cn_title' => '饰品快速取回', 'cn_sub_title' => '48h取回速率', 'cn_alter' => '', 'en_title' => 'Quick Retrieval of Accessories', 'en_sub_title' => '48-hour retrieval rate', 'en_alter' => ''],
]
],
Explanation:
- **Iterate through the 'profit_list' array.**2. For each element in the 'profit_list' array: - Identify 'cn_' prefixed keys. - Create corresponding 'en_' prefixed keys. - Copy the values of 'cn_' keys to their respective 'en_' counterparts.
This process ensures that the data is accessible to a broader audience, making the information more comprehensive and user-friendly.
原文地址: https://www.cveoy.top/t/topic/hpz5 著作权归作者所有。请勿转载和采集!